From d83e5c8a945dfb1f23d7498c34ec3a89ce6a3fb2 Mon Sep 17 00:00:00 2001 From: Ebubekir Date: Mon, 5 May 2025 19:40:40 +0930 Subject: [PATCH 1/2] Committing Feature Implementation for Issue 8088 --- lib/matplotlib/axes/_base.py | 9 ++++++--- lib/matplotlib/mpl-data/matplotlibrc | 1 + lib/matplotlib/mpl-data/stylelib/classic.mplstyle | 1 + lib/matplotlib/rcsetup.py | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 15f8e97b449f..a188b329ab54 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -680,7 +680,7 @@ def __init__(self, fig, raise ValueError('Width and height specified must be non-negative') self._originalPosition = self._position.frozen() self.axes = self - self._aspect = 'auto' + self._aspect = None self._adjustable = 'box' self._anchor = 'C' self._stale_viewlims = dict.fromkeys(self._axis_names, False) @@ -1656,9 +1656,12 @@ def get_aspect(self): """ Return the aspect ratio of the Axes scaling. - This is either "auto" or a float giving the ratio of y/x-scale. + This is either "auto", "equal" or a float giving the ratio of y/x-scale. """ - return self._aspect + if self._aspect: + return self._aspect + aspect = mpl.rcParams['axes.aspect'] + return aspect if aspect != 'equal' else 1 def set_aspect(self, aspect, adjustable=None, anchor=None, share=False): """ diff --git a/lib/matplotlib/mpl-data/matplotlibrc b/lib/matplotlib/mpl-data/matplotlibrc index 72117abf7317..a2b31bc7838b 100644 --- a/lib/matplotlib/mpl-data/matplotlibrc +++ b/lib/matplotlib/mpl-data/matplotlibrc @@ -390,6 +390,7 @@ #axes.labelpad: 4.0 # space between label and axis #axes.labelweight: normal # weight of the x and y labels #axes.labelcolor: black +#axes.aspect: auto # {auto, equal} or a number #axes.axisbelow: line # draw axis gridlines and ticks: # - below patches (True) # - above patches but below lines ('line') diff --git a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle index 6cba66076ac7..5dbf246dc1f6 100644 --- a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle @@ -185,6 +185,7 @@ axes.labelsize : medium # fontsize of the x any y labels axes.labelpad : 5.0 # space between label and axis axes.labelweight : normal # weight of the x and y labels axes.labelcolor : k +axes.aspect : auto # auto | equal | a number axes.axisbelow : False # whether axis gridlines and ticks are below # the axes elements (lines, text, etc) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index ce29c5076100..6afcbc84221e 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -1108,6 +1108,8 @@ def _convert_validator_spec(key, conv): "axes.spines.bottom": validate_bool, # denoting data boundary. "axes.spines.top": validate_bool, + "axes.aspect": validate_aspect, # auto, equal, a number + "axes.titlesize": validate_fontsize, # Axes title fontsize "axes.titlelocation": ["left", "center", "right"], # Axes title alignment "axes.titleweight": validate_fontweight, # Axes title font weight From ae95ad143a5a52641d41de57f296a05f39378fc6 Mon Sep 17 00:00:00 2001 From: Ebubekir Date: Sat, 24 May 2025 21:56:09 +0930 Subject: [PATCH 2/2] Fixing axes.aspect, and adding axes.adjustable --- lib/matplotlib/axes/_base.py | 11 ++++------- lib/matplotlib/mpl-data/matplotlibrc | 1 + lib/matplotlib/mpl-data/stylelib/classic.mplstyle | 1 + lib/matplotlib/rcsetup.py | 7 +++++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index a188b329ab54..fc97d511a8a0 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -680,8 +680,8 @@ def __init__(self, fig, raise ValueError('Width and height specified must be non-negative') self._originalPosition = self._position.frozen() self.axes = self - self._aspect = None - self._adjustable = 'box' + self._aspect = mpl.rcParams['axes.aspect'] + self._adjustable = mpl.rcParams['axes.adjustable'] self._anchor = 'C' self._stale_viewlims = dict.fromkeys(self._axis_names, False) self._forward_navigation_events = forward_navigation_events @@ -1656,12 +1656,9 @@ def get_aspect(self): """ Return the aspect ratio of the Axes scaling. - This is either "auto", "equal" or a float giving the ratio of y/x-scale. + This is either "auto" or a float giving the ratio of y/x-scale. """ - if self._aspect: - return self._aspect - aspect = mpl.rcParams['axes.aspect'] - return aspect if aspect != 'equal' else 1 + return self._aspect def set_aspect(self, aspect, adjustable=None, anchor=None, share=False): """ diff --git a/lib/matplotlib/mpl-data/matplotlibrc b/lib/matplotlib/mpl-data/matplotlibrc index 249c9f688757..e5c5377fd1e5 100644 --- a/lib/matplotlib/mpl-data/matplotlibrc +++ b/lib/matplotlib/mpl-data/matplotlibrc @@ -391,6 +391,7 @@ #axes.labelweight: normal # weight of the x and y labels #axes.labelcolor: black #axes.aspect: auto # {auto, equal} or a number +#axes.adjustable: box # box or datalim #axes.axisbelow: line # draw axis gridlines and ticks: # - below patches (True) # - above patches but below lines ('line') diff --git a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle index 5dbf246dc1f6..002f555cbcca 100644 --- a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle @@ -186,6 +186,7 @@ axes.labelpad : 5.0 # space between label and axis axes.labelweight : normal # weight of the x and y labels axes.labelcolor : k axes.aspect : auto # auto | equal | a number +axes.adjustable : box # box | datalim axes.axisbelow : False # whether axis gridlines and ticks are below # the axes elements (lines, text, etc) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 6afcbc84221e..d880d2804b56 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -397,8 +397,10 @@ def _validate_cmap(s): def validate_aspect(s): - if s in ('auto', 'equal'): + if s == 'auto': return s + if s == 'equal': + return 1 try: return float(s) except ValueError as e: @@ -1108,7 +1110,8 @@ def _convert_validator_spec(key, conv): "axes.spines.bottom": validate_bool, # denoting data boundary. "axes.spines.top": validate_bool, - "axes.aspect": validate_aspect, # auto, equal, a number + "axes.aspect": validate_aspect, # auto, equal, a number + "axes.adjustable": ["box", "datalim"], "axes.titlesize": validate_fontsize, # Axes title fontsize "axes.titlelocation": ["left", "center", "right"], # Axes title alignment