Vous êtes un professionnel et vous avez besoin d'une formation ?
Coder avec une
Intelligence Artificielle
Voir le programme détaillé
Classe « Axes »
Signature de la méthode secondary_xaxis
def secondary_xaxis(self, location, functions=None, *, transform=None, **kwargs)
Description
help(Axes.secondary_xaxis)
Add a second x-axis to this `~.axes.Axes`.
For example if we want to have a second scale for the data plotted on
the xaxis.
Warnings
--------
This method is experimental as of 3.1, and the API may change.
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' for
orientation='y'. A float indicates the relative position on the
parent Axes to put the new Axes, 0.0 being the bottom (or left)
and 1.0 being the top (or right).
functions : 2-tuple of func, or Transform with an inverse
If a 2-tuple of functions, the user specifies the transform
function and its inverse. i.e.
``functions=(lambda x: 2 / x, lambda x: 2 / x)`` would be an
reciprocal transform with a factor of 2. Both functions must accept
numpy arrays as input.
The user can also directly supply a subclass of
`.transforms.Transform` so long as it has an inverse.
See :doc:`/gallery/subplots_axes_and_figures/secondary_axis`
for examples of making these conversions.
transform : `.Transform`, optional
If specified, *location* will be
placed relative to this transform (in the direction of the axis)
rather than the parent's axis. i.e. a secondary x-axis will
use the provided y transform and the x transform of the parent.
.. versionadded:: 3.9
Returns
-------
ax : axes._secondary_axes.SecondaryAxis
Other Parameters
----------------
**kwargs : `~matplotlib.axes.Axes` properties.
Other miscellaneous Axes parameters.
Examples
--------
The main axis shows frequency, and the secondary axis shows period.
.. plot::
fig, ax = plt.subplots()
ax.loglog(range(1, 360, 5), range(1, 360, 5))
ax.set_xlabel('frequency [Hz]')
def invert(x):
# 1/x with special treatment of x == 0
x = np.array(x).astype(float)
near_zero = np.isclose(x, 0)
x[near_zero] = np.inf
x[~near_zero] = 1 / x[~near_zero]
return x
# the inverse of 1/x is itself
secax = ax.secondary_xaxis('top', functions=(invert, invert))
secax.set_xlabel('Period [s]')
plt.show()
To add a secondary axis relative to your data, you can pass a transform
to the new axis.
.. plot::
fig, ax = plt.subplots()
ax.plot(range(0, 5), range(-1, 4))
# Pass 'ax.transData' as a transform to place the axis
# relative to your data at y=0
secax = ax.secondary_xaxis(0, transform=ax.transData)
Vous êtes un professionnel et vous avez besoin d'une formation ?
Machine Learning
avec Scikit-Learn
Voir le programme détaillé
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :