File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
examples/subplots_axes_and_figures Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ def inverse(x):
111
111
112
112
dates = [datetime .datetime (2018 , 1 , 1 ) + datetime .timedelta (hours = k * 6 )
113
113
for k in range (240 )]
114
- temperature = np .random .randn (len (dates ))
114
+ temperature = np .random .randn (len (dates )) * 4 + 6.7
115
115
fig , ax = plt .subplots (constrained_layout = True )
116
116
117
117
ax .plot (dates , temperature )
@@ -147,6 +147,21 @@ def fahrenheit_to_celsius(x):
147
147
'right' , functions = (celsius_to_fahrenheit , fahrenheit_to_celsius ))
148
148
secax_y .set_ylabel (r'$T\ [^oF]$' )
149
149
150
+
151
+ def celsius_to_anomaly (x ):
152
+ return (x - np .mean (temperature ))
153
+
154
+
155
+ def anomaly_to_celsius (x ):
156
+ return (x + np .mean (temperature ))
157
+
158
+
159
+ # document use of a float for the position:
160
+ secax_y2 = ax .secondary_yaxis (
161
+ 1.2 , functions = (celsius_to_anomaly , anomaly_to_celsius ))
162
+ secax_y2 .set_ylabel (r'$T - \overline{T}\ [^oC]$' )
163
+
164
+
150
165
plt .show ()
151
166
152
167
#############################################################################
You can’t perform that action at this time.
0 commit comments