@@ -106,12 +106,13 @@ def inverse(x):
106106
107107###########################################################################
108108# A final example translates np.datetime64 to yearday on the x axis and
109- # from Celsius to Fahrenheit on the y axis:
110-
109+ # from Celsius to Fahrenheit on the y axis. Note the addition of a
110+ # third y axis, and that it can be placed using a float for the
111+ # location argument
111112
112113dates = [datetime .datetime (2018 , 1 , 1 ) + datetime .timedelta (hours = k * 6 )
113114 for k in range (240 )]
114- temperature = np .random .randn (len (dates ))
115+ temperature = np .random .randn (len (dates )) * 4 + 6.7
115116fig , ax = plt .subplots (constrained_layout = True )
116117
117118ax .plot (dates , temperature )
@@ -147,6 +148,21 @@ def fahrenheit_to_celsius(x):
147148 'right' , functions = (celsius_to_fahrenheit , fahrenheit_to_celsius ))
148149secax_y .set_ylabel (r'$T\ [^oF]$' )
149150
151+
152+ def celsius_to_anomaly (x ):
153+ return (x - np .mean (temperature ))
154+
155+
156+ def anomaly_to_celsius (x ):
157+ return (x + np .mean (temperature ))
158+
159+
160+ # use of a float for the position:
161+ secax_y2 = ax .secondary_yaxis (
162+ 1.2 , functions = (celsius_to_anomaly , anomaly_to_celsius ))
163+ secax_y2 .set_ylabel (r'$T - \overline{T}\ [^oC]$' )
164+
165+
150166plt .show ()
151167
152168#############################################################################
0 commit comments