flâneur

Plots with different scales — Matplotlib 3.5.3 documentation

matplotlib.org · 201 words · saved by 1 readers

The trick is to use two different axes that share the same x axis. You can use separate matplotlib.ticker formatters and locators as desired since the two axes are independent. Such axes are generated by calling the Axes.twinx method. Likewise, Axes.twiny is available to generate axes that share a y axis but have different top and bottom scales. References The use of the following functions, methods, classes and modules is shown in this example: matplotlib.axes.Axes.twinx / matplotlib.pyplot.twinx matplotlib.axes.Axes.twiny / matplotlib.pyplot.twiny matplotlib.axes.Axes.tick_params / matplotlib.pyplot.tick_params Download Python source code: two_scales.py Download Jupyter notebook: two_scales.ipynb Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery © Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2022 The Matplotlib development team. Created using Sphinx 4.5.0.

Note Go to the end to download the full example code. Two plots on the same Axes with different left and right scales. The trick is to use two different Axes that share the same x axis. You can use separate matplotlib.ticker formatters and locators as desired since the two Axes are independent. Such Axes are generated by calling the Axes.twinx method. Likewise, Axes.twiny is available to generate Axes that share a y axis but have different top and bottom scales. See also Secondary Axis for the case where the two scales are not independent, but related (e.g., the same quantity in two…

saved by

related reading