41
41
42
42
rcParams = matplotlib .rcParams
43
43
44
-
45
44
def _has_item (data , name ):
46
45
"""Return whether *data* can be item-accessed with *name*.
47
46
@@ -637,56 +636,16 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
637
636
638
637
return rectpatch , connects
639
638
640
- def secondary_xaxis (self , location , * , conversion = None ,
641
- otherargs = None , ** kwargs ):
639
+
640
+ @docstring .dedent_interpd
641
+ def secondary_xaxis (self , location , * , conversion = None , ** kwargs ):
642
642
"""
643
643
Add a second x-axis to this axes.
644
644
645
645
For example if we want to have a second scale for the data plotted on
646
646
the xaxis.
647
-
648
- Warnings
649
- --------
650
-
651
- This method is experimental as of 3.1, and the API may change.
652
-
653
- Parameters
654
- ----------
655
- location : string or scalar
656
- The position to put the secondary axis. Strings can be 'top' or
657
- 'bottom', scalar can be a float indicating the relative position
658
- on the axes to put the new axes (0 being the bottom, and 1.0 being
659
- the top.)
660
-
661
- conversion : scalar, two-tuple of scalars, string, or Transform
662
- If a scalar or a two-tuple of scalar, the secondary axis is
663
- converted via a linear conversion with slope given by the first
664
- and offset given by the second. i.e. ``conversion = [2, 1]``
665
- element for a parent axis between 0 and 1 gives a secondary axis
666
- between 1 and 3.
667
-
668
- If a string, if can be one of "linear", "power", and "inverted".
669
- If "linear", the value of ``otherargs`` should be a float or
670
- two-tuple as above. If "inverted" the values in the secondary axis
671
- are inverted and multiplied by the value supplied by ``oterargs``.
672
- If "power", then the original values are transformed by
673
- ``newx = otherargs[1] * oldx ** otherargs[0]``.
674
-
675
- Finally, the user can supply a subclass of `.transforms.Transform`
676
- to arbitrarily transform between the parent axes and the
677
- secondary axes.
678
- See :doc:`/gallery/subplots_axes_and_figures/secondary_axis`
679
- for an example of making such a transform.
680
-
681
-
682
- Other Parameters
683
- ----------------
684
- **kwargs : `~matplotlib.axes.Axes` properties.
685
- Other miscellaneous axes parameters.
686
-
687
- Returns
688
- -------
689
- ax : axes._secondary_axes.Secondary_Axis
647
+
648
+ %(_secax_docstring)s
690
649
691
650
Examples
692
651
--------
@@ -699,72 +658,30 @@ def secondary_xaxis(self, location, *, conversion=None,
699
658
fig, ax = plt.subplots()
700
659
ax.loglog(range(1, 360, 5), range(1, 360, 5))
701
660
ax.set_xlabel('wavenumber [cpkm]')
702
- secax = ax.secondary_xaxis('top', conversion='inverted' ,
703
- otherargs=1. )
661
+ secax = ax.secondary_xaxis('top', conversion=(lambda x: 1 / x ,
662
+ lambda x: 1 / x) )
704
663
secax.set_xlabel('wavelength [km]')
664
+ plt.show()
705
665
706
666
707
667
"""
708
668
if (location in ['top' , 'bottom' ] or isinstance (location , Number )):
709
669
secondary_ax = Secondary_Axis (self , 'x' , location ,
710
- conversion , otherargs = otherargs ,
711
- ** kwargs )
670
+ conversion , ** kwargs )
712
671
self .add_child_axes (secondary_ax )
713
672
return secondary_ax
714
673
else :
715
674
raise ValueError ('secondary_xaxis location must be either '
716
675
'"top" or "bottom"' )
717
676
718
- def secondary_yaxis (self , location , * , conversion = None ,
719
- otherargs = None , ** kwargs ):
677
+ def secondary_yaxis (self , location , * , conversion = None , ** kwargs ):
720
678
"""
721
679
Add a second y-axis to this axes.
722
680
723
681
For example if we want to have a second scale for the data plotted on
724
- the xaxis.
725
-
726
- Warnings
727
- --------
728
-
729
- This method is experimental as of 3.1, and the API may change.
682
+ the yaxis.
730
683
731
- Parameters
732
- ----------
733
- location : string or scalar
734
- The position to put the secondary axis. Strings can be 'left' or
735
- 'right', scalar can be a float indicating the relative position
736
- on the axes to put the new axes (0 being the left, and 1.0 being
737
- the right.)
738
-
739
- conversion : scalar, two-tuple of scalars, string, or Transform
740
- If a scalar or a two-tuple of scalar, the secondary axis is
741
- converted via a linear conversion with slope given by the first
742
- and offset given by the second. i.e. ``conversion = [2, 1]``
743
- element for a parent axis between 0 and 1 gives a secondary axis
744
- between 1 and 3.
745
-
746
- If a string, if can be one of "linear", "power", and "inverted".
747
- If "linear", the value of ``otherargs`` should be a float or
748
- two-tuple as above. If "inverted" the values in the secondary axis
749
- are inverted and multiplied by the value supplied by ``oterargs``.
750
- If "power", then the original values are transformed by
751
- ``newy = otherargs[1] * oldy ** otherargs[0]``.
752
-
753
- Finally, the user can supply a subclass of `.transforms.Transform`
754
- to arbitrarily transform between the parent axes and the
755
- secondary axes.
756
- See :doc:`/gallery/subplots_axes_and_figures/secondary_axis`
757
- for an example of making such a transform.
758
-
759
-
760
- Other Parameters
761
- ----------------
762
- **kwargs : `~matplotlib.axes.Axes` properties.
763
- Other miscellaneous axes parameters.
764
-
765
- Returns
766
- -------
767
- ax : axes._secondary_axes.Secondary_Axis
684
+ %(_secax_docstring)s
768
685
769
686
Examples
770
687
--------
@@ -782,8 +699,7 @@ def secondary_yaxis(self, location, *, conversion=None,
782
699
"""
783
700
if location in ['left' , 'right' ] or isinstance (location , Number ):
784
701
secondary_ax = Secondary_Axis (self , 'y' , location ,
785
- conversion , otherargs = otherargs ,
786
- ** kwargs )
702
+ conversion , ** kwargs )
787
703
self .add_child_axes (secondary_ax )
788
704
return secondary_ax
789
705
else :
0 commit comments