@@ -106,12 +106,13 @@ def inverse(x):
106
106
107
107
###########################################################################
108
108
# 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
111
112
112
113
dates = [datetime .datetime (2018 , 1 , 1 ) + datetime .timedelta (hours = k * 6 )
113
114
for k in range (240 )]
114
- temperature = np .random .randn (len (dates ))
115
+ temperature = np .random .randn (len (dates )) * 4 + 6.7
115
116
fig , ax = plt .subplots (constrained_layout = True )
116
117
117
118
ax .plot (dates , temperature )
@@ -147,6 +148,21 @@ def fahrenheit_to_celsius(x):
147
148
'right' , functions = (celsius_to_fahrenheit , fahrenheit_to_celsius ))
148
149
secax_y .set_ylabel (r'$T\ [^oF]$' )
149
150
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
+ # document 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
+
150
166
plt .show ()
151
167
152
168
#############################################################################
0 commit comments