Skip to content

Better document Axes.transData and other transXYZ attributes #25922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/axes_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ non-rectilinear Axes.
Axes.get_yaxis_text1_transform
Axes.get_yaxis_text2_transform

Axes.transAxes
Axes.transScale
Axes.transLimits
Axes.transData


Other
=====
Expand Down
59 changes: 59 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,65 @@ class _AxesBase(martist.Artist):

_subclass_uses_cla = False

@property
def transAxes(self):
"""
Transform object that represents a coordinate system relative
to the axes of a plot. It provides a mapping from coordinates specified
as fractions of the axes' dimensions. The origin of this coordinate
system (0, 0) is located at the bottom-left corner of the axes, while the
top-right corner is represented by the coordinates (1, 1).
"""
return self._transAxes

@transAxes.setter
def transAxes(self, value):
self._transAxes = value

@property
def transScale(self):
"""
Transform object that represents the scaling transformation for
the data coordinates within an axes. It is responsible for converting
the data coordinates to scaled coordinates used for rendering the plot.
The transformation incorporates the scaling applied to the data
along both the x-axis and the y-axis.
"""
return self._transScale

@transScale.setter
def transScale(self, value):
self._transScale = value

@property
def transLimits(self):
"""
Transform object that represents the transformation from data
coordinates to the coordinate system used for drawing within the axes
limits. It maps the range of data coordinates to the corresponding range
of the axes limits, taking into account any data clipping that might occur.
"""
return self._transLimits

@transLimits.setter
def transLimits(self, value):
self._transLimits = value

@property
def transData(self):
"""
Transform object that represents the transformation from data
coordinates to the coordinate system used for drawing within the axes.
It converts the data coordinates of a plot to the corresponding coordinate
values in the drawing space, enabling proper rendering of plot elements
relative to the axes and the figure.
"""
return self._transData

@transData.setter
def transData(self, value):
self._transData = value

@property
def _axis_map(self):
"""A mapping of axis names, e.g. 'x', to `Axis` instances."""
Expand Down
24 changes: 20 additions & 4 deletions lib/matplotlib/axes/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class _AxesBase(martist.Artist):
yaxis: YAxis
bbox: Bbox
dataLim: Bbox
transAxes: Transform
transScale: Transform
transLimits: Transform
transData: Transform
_transAxes: Transform
_transScale: Transform
_transLimits: Transform
_transData: Transform
ignore_existing_data_limits: bool
axison: bool
_projection_init: Any
Expand All @@ -68,6 +68,22 @@ class _AxesBase(martist.Artist):
box_aspect: float | None = ...,
**kwargs
) -> None: ...
@property
def transAxes(self) -> Transform: ...
@transAxes.setter
def transAxes(self, value: Transform) -> None: ...
@property
def transScale(self) -> Transform: ...
@transScale.setter
def transScale(self, value: Transform) -> None: ...
@property
def transLimits(self) -> Transform: ...
@transLimits.setter
def transLimits(self, value: Transform) -> None: ...
@property
def transData(self) -> Transform: ...
@transData.setter
def transData(self, value: Transform) -> None: ...
def get_subplotspec(self) -> SubplotSpec | None: ...
def set_subplotspec(self, subplotspec: SubplotSpec) -> None: ...
def get_gridspec(self) -> GridSpec | None: ...
Expand Down