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

Skip to content

Commit 0750e20

Browse files
committed
Basic Usage tutorial: add additional axes section
Secondary and twin axes are rather important (although not necessarily very basic) so they should be shortly mentioned with links to the API docs and some more detailed examples.
1 parent 8774ce4 commit 0750e20

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tutorials/introductory/usage.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ def my_plotter(ax, data1, data2, param_dict):
367367
#
368368
# Each Axes has two (or three) `~.axis.Axis` objects representing the x- and
369369
# y-axis. These control the *scale* of the Axis, the tick *locators* and the
370-
# tick *formatters*.
370+
# tick *formatters*. Additional Axes can be attached to display further Axis
371+
# objects.
371372
#
372373
# Scales
373374
# ------
@@ -449,6 +450,34 @@ def my_plotter(ax, data1, data2, param_dict):
449450
# numbers or dates. If you pass 1000 strings, Matplotlib will think you
450451
# meant 1000 categories and will add 1000 ticks to your plot!
451452
#
453+
#
454+
# Additional Axis objects
455+
# ------------------------
456+
#
457+
# Plotting data of different magnitude in one chart may require
458+
# an additional y-axis. Such an Axis can be created by using
459+
# `~.Axes.twinx` to add a new Axes with an invisible x-axis and a y-axis
460+
# positioned at the right (analogously for `~.Axes.twiny`). See
461+
# :doc:`/gallery/subplots_axes_and_figures/two_scales` for another example.
462+
#
463+
# Similarly, you can add a `~.Axes.secondary_xaxis` or
464+
# `~.Axes.secondary_yaxis` having a different scale than the main Axis to
465+
# represent the data in different scales or units. See
466+
# :doc:`/gallery/subplots_axes_and_figures/secondary_axis` for further
467+
# examples.
468+
469+
fig, (ax1, ax3) = plt.subplots(1, 2, figsize=(8, 2.7), constrained_layout=True)
470+
l1, = ax1.plot(t, s)
471+
ax2 = ax1.twinx()
472+
l2, = ax2.plot(t, range(len(t)), 'C1')
473+
ax2.legend([l1, l2], ['Sine (left)', 'Straight (right)'])
474+
475+
ax3.plot(t, s)
476+
ax3.set_xlabel('Angle [°]')
477+
ax4 = ax3.secondary_xaxis('top', functions=(np.rad2deg, np.deg2rad))
478+
ax4.set_xlabel('Angle [rad]')
479+
480+
##############################################################################
452481
# Color mapped data
453482
# =================
454483
#

0 commit comments

Comments
 (0)