Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebcda9a

Browse files
committed
DOC: add offset axes to secondary_axes
1 parent d9d5077 commit ebcda9a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

examples/subplots_axes_and_figures/secondary_axis.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def inverse(x):
111111

112112
dates = [datetime.datetime(2018, 1, 1) + datetime.timedelta(hours=k * 6)
113113
for k in range(240)]
114-
temperature = np.random.randn(len(dates))
114+
temperature = np.random.randn(len(dates)) * 4 + 6.7
115115
fig, ax = plt.subplots(constrained_layout=True)
116116

117117
ax.plot(dates, temperature)
@@ -147,6 +147,21 @@ def fahrenheit_to_celsius(x):
147147
'right', functions=(celsius_to_fahrenheit, fahrenheit_to_celsius))
148148
secax_y.set_ylabel(r'$T\ [^oF]$')
149149

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+
150165
plt.show()
151166

152167
#############################################################################

0 commit comments

Comments
 (0)