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 4 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
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 'auto'
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
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@
#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.adjustable: box # box or datalim
#axes.axisbelow: line # draw axis gridlines and ticks:
# - below patches (True)
# - above patches but below lines ('line')
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ 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.adjustable : box # box | datalim
axes.axisbelow : False # whether axis gridlines and ticks are below
# the axes elements (lines, text, etc)

Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1108,6 +1110,9 @@ 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.adjustable": ["box", "datalim"],

"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