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

Skip to content

Commit 6a89fda

Browse files
authored
Merge pull request #14904 from bingyao/typo_fix_in_an_example
Fix typo in secondary_axis.py example.
2 parents bc2f53b + 7901dbb commit 6a89fda

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

examples/subplots_axes_and_figures/secondary_axis.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Secondary Axis
44
==============
55
6-
Sometimes we want as secondary axis on a plot, for instance to convert
6+
Sometimes we want a secondary axis on a plot, for instance to convert
77
radians to degrees on the same plot. We can do this by making a child
88
axes with only one axis visible via `.Axes.axes.secondary_xaxis` and
99
`.Axes.axes.secondary_yaxis`. This secondary axis can have a different scale
@@ -35,6 +35,7 @@ def deg2rad(x):
3535
def rad2deg(x):
3636
return x * 180 / np.pi
3737

38+
3839
secax = ax.secondary_xaxis('top', functions=(deg2rad, rad2deg))
3940
secax.set_xlabel('angle [rad]')
4041
plt.show()
@@ -65,6 +66,7 @@ def forward(x):
6566
def inverse(x):
6667
return 1 / x
6768

69+
6870
secax = ax.secondary_xaxis('top', functions=(forward, inverse))
6971
secax.set_xlabel('period [s]')
7072
plt.show()
@@ -97,6 +99,7 @@ def forward(x):
9799
def inverse(x):
98100
return np.interp(x, xnew, xold)
99101

102+
100103
secax = ax.secondary_xaxis('top', functions=(forward, inverse))
101104
secax.xaxis.set_minor_locator(AutoMinorLocator())
102105
secax.set_xlabel('$X_{other}$')
@@ -109,7 +112,7 @@ def inverse(x):
109112

110113

111114
dates = [datetime.datetime(2018, 1, 1) + datetime.timedelta(hours=k * 6)
112-
for k in range(240)]
115+
for k in range(240)]
113116
temperature = np.random.randn(len(dates))
114117
fig, ax = plt.subplots(constrained_layout=True)
115118

@@ -129,6 +132,7 @@ def yday2date(x):
129132
y = x + mdates.date2num(datetime.datetime(2018, 1, 1))
130133
return y
131134

135+
132136
secaxx = ax.secondary_xaxis('top', functions=(date2yday, yday2date))
133137
secaxx.set_xlabel('yday [2018]')
134138

@@ -140,6 +144,7 @@ def CtoF(x):
140144
def FtoC(x):
141145
return (x - 32) / 1.8
142146

147+
143148
secaxy = ax.secondary_yaxis('right', functions=(CtoF, FtoC))
144149
secaxy.set_ylabel(r'$T\ [^oF]$')
145150

0 commit comments

Comments
 (0)