Skip to content

Allow setting of aspect ratio for Axes in rcParams - Draft PR #30017

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 6 additions & 3 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._aspect = None
self._aspect = mpl.rcParams['axes.aspect']

Resolution should happen at initialization.

self._adjustable = 'box'
self._anchor = 'C'
self._stale_viewlims = dict.fromkeys(self._axis_names, False)
Expand Down Expand Up @@ -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
Comment on lines -1659 to +1664
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not change anything here. rcParams lookup should be in __init__. Normalization "equal" -> 1 can be done in validate_aspect, so that "equal" is only public API but never internal state.


def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
"""
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy