20
20
21
21
def two_scales (ax1 , time , data1 , data2 , c1 , c2 ):
22
22
"""
23
-
24
23
Parameters
25
24
----------
26
- ax : axis
25
+ ax1 : axis
27
26
Axis to put two scales on
28
27
29
28
time : array-like
@@ -43,10 +42,11 @@ def two_scales(ax1, time, data1, data2, c1, c2):
43
42
44
43
Returns
45
44
-------
46
- ax : axis
45
+ ax1 : axis
47
46
Original axis
48
47
ax2 : axis
49
48
New twin axis
49
+
50
50
"""
51
51
ax2 = ax1 .twinx ()
52
52
@@ -56,8 +56,8 @@ def two_scales(ax1, time, data1, data2, c1, c2):
56
56
57
57
ax2 .plot (time , data2 , color = c2 )
58
58
ax2 .set_ylabel ('sin' )
59
- return ax1 , ax2
60
59
60
+ return ax1 , ax2
61
61
62
62
# Create some mock data
63
63
t = np .arange (0.01 , 10.0 , 0.01 )
@@ -68,7 +68,6 @@ def two_scales(ax1, time, data1, data2, c1, c2):
68
68
fig , ax = plt .subplots ()
69
69
ax1 , ax2 = two_scales (ax , t , s1 , s2 , 'r' , 'b' )
70
70
71
-
72
71
# Change color of each axis
73
72
def color_y_axis (ax , color ):
74
73
"""Color your axes."""
@@ -77,4 +76,6 @@ def color_y_axis(ax, color):
77
76
return None
78
77
color_y_axis (ax1 , 'r' )
<
4868
/tr>79
78
color_y_axis (ax2 , 'b' )
79
+
80
+ fig .tight_layout () # otherwise y-labels are slightly clipped
80
81
plt .show ()
0 commit comments