matplotlib.axes.Axes.secondary_xaxis#

Axes.secondary_xaxis(location,functions=None,*,transform=None,**kwargs)[source]#

Add a second x-axis to thisAxes.

For example if we want to have a second scale for the data plotted onthe xaxis.

Parameters:
location{'top', 'bottom', 'left', 'right'} or float

The position to put the secondary axis. Strings can be 'top' or'bottom' for orientation='x' and 'right' or 'left' fororientation='y'. A float indicates the relative position on theparent Axes to put the new Axes, 0.0 being the bottom (or left)and 1.0 being the top (or right).

functions2-tuple of func, or Transform with an inverse

If a 2-tuple of functions, the user specifies the transformfunction and its inverse. i.e.functions=(lambdax:2/x,lambdax:2/x) would be anreciprocal transform with a factor of 2. Both functions must acceptnumpy arrays as input.

The user can also directly supply a subclass oftransforms.Transform so long as it has an inverse.

SeeSecondary Axisfor examples of making these conversions.

transformTransform, optional

If specified,location will beplaced relative to this transform (in the direction of the axis)rather than the parent's axis. i.e. a secondary x-axis willuse the provided y transform and the x transform of the parent.

Added in version 3.9.

Returns:
axaxes._secondary_axes.SecondaryAxis
Other Parameters:
**kwargsAxes properties.

Other miscellaneous Axes parameters.

Warning

This method is experimental as of 3.1, and the API may change.

Examples

The main axis shows frequency, and the secondary axis shows period.

(Sourcecode,2x.png,png)

To add a secondary axis relative to your data, you can pass a transformto the new axis.

(Sourcecode,2x.png,png)

Examples usingmatplotlib.axes.Axes.secondary_xaxis#

Secondary Axis

Secondary Axis

Multilevel (nested) ticks

Multilevel (nested) ticks

Quick start guide

Quick start guide