2020
2121def two_scales (ax1 , time , data1 , data2 , c1 , c2 ):
2222 """
23-
2423 Parameters
2524 ----------
26- ax : axis
25+ ax1 : axis
2726 Axis to put two scales on
2827
2928 time : array-like
@@ -43,10 +42,11 @@ def two_scales(ax1, time, data1, data2, c1, c2):
4342
4443 Returns
4544 -------
46- ax : axis
45+ ax1 : axis
4746 Original axis
4847 ax2 : axis
4948 New twin axis
49+
5050 """
5151 ax2 = ax1 .twinx ()
5252
@@ -56,8 +56,8 @@ def two_scales(ax1, time, data1, data2, c1, c2):
5656
5757 ax2 .plot (time , data2 , color = c2 )
5858 ax2 .set_ylabel ('sin' )
59- return ax1 , ax2
6059
60+ return ax1 , ax2
6161
6262# Create some mock data
6363t = np .arange (0.01 , 10.0 , 0.01 )
@@ -68,7 +68,6 @@ def two_scales(ax1, time, data1, data2, c1, c2):
6868fig , ax = plt .subplots ()
6969ax1 , ax2 = two_scales (ax , t , s1 , s2 , 'r' , 'b' )
7070
71-
7271# Change color of each axis
7372def color_y_axis (ax , color ):
7473 """Color your axes."""
@@ -77,4 +76,6 @@ def color_y_axis(ax, color):
7776 return None
7877color_y_axis (ax1 , 'r' )
7978color_y_axis (ax2 , 'b' )
79+
80+ fig .tight_layout () # otherwise y-labels are slightly clipped
8081plt .show ()
0 commit comments