Add a second y-axis to this `~.axes.Axes`. This axis is typically used to display a second y-scale for the data plotted on the Axes. %(_secax_docstring)s Examples -------- Add a secondary Axes that converts from radians to degrees
(self, location, functions=None, *, transform=None, **kwargs)
| 607 | |
| 608 | @_docstring.interpd |
| 609 | def secondary_yaxis(self, location, functions=None, *, transform=None, **kwargs): |
| 610 | """ |
| 611 | Add a second y-axis to this `~.axes.Axes`. |
| 612 | |
| 613 | This axis is typically used to display a second y-scale for the data |
| 614 | plotted on the Axes. |
| 615 | |
| 616 | %(_secax_docstring)s |
| 617 | |
| 618 | Examples |
| 619 | -------- |
| 620 | Add a secondary Axes that converts from radians to degrees |
| 621 | |
| 622 | .. plot:: |
| 623 | |
| 624 | fig, ax = plt.subplots() |
| 625 | ax.plot(range(1, 360, 5), range(1, 360, 5)) |
| 626 | ax.set_ylabel('degrees') |
| 627 | secax = ax.secondary_yaxis('right', functions=(np.deg2rad, |
| 628 | np.rad2deg)) |
| 629 | secax.set_ylabel('radians') |
| 630 | |
| 631 | To add a secondary axis relative to your data, you can pass a transform |
| 632 | to the new axis. |
| 633 | |
| 634 | .. plot:: |
| 635 | |
| 636 | fig, ax = plt.subplots() |
| 637 | ax.plot(range(0, 5), range(-1, 4)) |
| 638 | |
| 639 | # Pass 'ax.transData' as a transform to place the axis |
| 640 | # relative to your data at x=3 |
| 641 | secax = ax.secondary_yaxis(3, transform=ax.transData) |
| 642 | """ |
| 643 | if not (location in ['left', 'right'] or isinstance(location, Real)): |
| 644 | raise ValueError('secondary_yaxis location must be either ' |
| 645 | 'a float or "left"/"right"') |
| 646 | |
| 647 | secondary_ax = SecondaryAxis(self, 'y', location, functions, |
| 648 | transform, **kwargs) |
| 649 | self.add_child_axes(secondary_ax) |
| 650 | return secondary_ax |
| 651 | |
| 652 | @_docstring.interpd |
| 653 | def text(self, x, y, s, fontdict=None, **kwargs): |