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

Skip to content

Fix typo in secondary_axis.py example. #14904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/subplots_axes_and_figures/secondary_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Secondary Axis
==============

Sometimes we want as secondary axis on a plot, for instance to convert
Sometimes we want a secondary axis on a plot, for instance to convert
radians to degrees on the same plot. We can do this by making a child
axes with only one axis visible via `.Axes.axes.secondary_xaxis` and
`.Axes.axes.secondary_yaxis`. This secondary axis can have a different scale
Expand Down Expand Up @@ -35,6 +35,7 @@ def deg2rad(x):
def rad2deg(x):
return x * 180 / np.pi


secax = ax.secondary_xaxis('top', functions=(deg2rad, rad2deg))
secax.set_xlabel('angle [rad]')
plt.show()
Expand Down Expand Up @@ -65,6 +66,7 @@ def forward(x):
def inverse(x):
return 1 / x


secax = ax.secondary_xaxis('top', functions=(forward, inverse))
secax.set_xlabel('period [s]')
plt.show()
Expand Down Expand Up @@ -97,6 +99,7 @@ def forward(x):
def inverse(x):
return np.interp(x, xnew, xold)


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


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

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


secaxx = ax.secondary_xaxis('top', functions=(date2yday, yday2date))
secaxx.set_xlabel('yday [2018]')

Expand All @@ -140,6 +144,7 @@ def CtoF(x):
def FtoC(x):
return (x - 32) / 1.8


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

Expand Down