Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4b78bba

Browse filesBrowse files
committed
Add rcParams for Axes creation
1 parent 7fdf772 commit 4b78bba
Copy full SHA for 4b78bba

File tree

5 files changed

+74
-15
lines changed
Filter options

5 files changed

+74
-15
lines changed
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
New rcParams for Axes creation
2+
------------------------------
3+
4+
A number of rcParams are introduced to control parts of the Axes creation.
5+
For a standard 2D Axes, the following are introduced:
6+
7+
* :rc:`axes.adjustable`, see `.Axes.set_adjustable`
8+
* :rc:`axes.anchor`, see `.Axes.set_anchor`
9+
* :rc:`axes.aspect`, see `.Axes.set_aspect`
10+
* :rc:`axes.box_aspect`, see `.Axes.set_box_aspect`
11+
12+
There are separate parameters for 3D Axes, including an additional 3D-specific one:
13+
14+
* :rc:`axes3d.adjustable`, see `.Axes.set_adjustable`
15+
* :rc:`axes3d.anchor`, see `.Axes.set_anchor`
16+
* :rc:`axes3d.aspect`, see `.Axes3D.set_aspect`
17+
* :rc:`axes3d.box_aspect`, see `.Axes3D.set_box_aspect`
18+
* :rc:`axes3d.proj_type`, see `.Axes3D.set_proj_type`

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,9 @@ def __init__(self, fig,
646646
raise ValueError('Width and height specified must be non-negative')
647647
self._originalPosition = self._position.frozen()
648648
self.axes = self
649-
self._aspect = 'auto'
650-
self._adjustable = 'box'
651-
self._anchor = 'C'
649+
self._aspect = mpl.rcParams['axes.aspect']
650+
self._adjustable = mpl.rcParams['axes.adjustable']
651+
self._anchor = mpl.rcParams['axes.anchor']
652652
self._stale_viewlims = {name: False for name in self._axis_names}
653653
self._sharex = sharex
654654
self._sharey = sharey

‎lib/matplotlib/mpl-data/matplotlibrc

Copy file name to clipboardExpand all lines: lib/matplotlib/mpl-data/matplotlibrc
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,19 @@
425425
#axes.autolimit_mode: data # If "data", use axes.xmargin and axes.ymargin as is.
426426
# If "round_numbers", after application of margins, axis
427427
# limits are further expanded to the nearest "round" number.
428-
#polaraxes.grid: True # display grid on polar axes
429-
#axes3d.grid: True # display grid on 3D axes
428+
#axes.adjustable: box # {box, adjustable}
429+
#axes.anchor: C # {C, E, N, S, W, NE, NW, SE, SW} or two-tuple of floats
430+
#axes.aspect: auto # {equal, auto} or a number
431+
#axes.box_aspect: None # None or a number
432+
433+
#polaraxes.grid: True # display grid on polar axes
434+
435+
#axes3d.grid: True # display grid on 3D axes
436+
#axes3d.adjustable: box # {box, adjustable}
437+
#axes3d.anchor: C # {C, E, N, S, W, NE, NW, SE, SW} or two-tuple of floats
438+
#axes3d.aspect: auto
439+
#axes3d.box_aspect: 4, 4, 3 # three floats: x, y, z
440+
#axes3d.proj_type: persp # {persp, ortho}
430441

431442
#axes3d.xaxis.panecolor: (0.95, 0.95, 0.95, 0.5) # background pane on 3D axes
432443
#axes3d.yaxis.panecolor: (0.90, 0.90, 0.90, 0.5) # background pane on 3D axes

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ def validate_aspect(s):
347347
raise ValueError('not a valid aspect specification') from e
348348

349349

350+
def validate_anchor(s):
351+
if s in ('C', 'E', 'N', 'S', 'W', 'NE', 'NW', 'SE', 'SW'):
352+
return s
353+
if isinstance(s, tuple):
354+
try:
355+
return (float(s[0]), float(s[1]))
356+
except ValueError as e:
357+
raise ValueError('not a valid anchor specification') from e
358+
raise ValueError(f'not a valid anchor specification: {s!r}')
359+
360+
350361
def validate_fontsize_None(s):
351362
if s is None or s == 'None':
352363
return None
@@ -1015,9 +1026,18 @@ def _convert_validator_spec(key, conv):
10151026
"axes.xmargin": _range_validators["0 <= x <= 1"], # margin added to xaxis
10161027
"axes.ymargin": _range_validators["0 <= x <= 1"], # margin added to yaxis
10171028
'axes.zmargin': _range_validators["0 <= x <= 1"], # margin added to zaxis
1029+
"axes.adjustable": ["box", "datalim"],
1030+
"axes.anchor": validate_anchor,
1031+
"axes.aspect": validate_aspect, # equal, auto, a number
1032+
"axes.box_aspect": validate_float_or_None,
10181033

10191034
"polaraxes.grid": validate_bool, # display polar grid or not
10201035
"axes3d.grid": validate_bool, # display 3d grid
1036+
"axes3d.adjustable": ["box", "datalim"],
1037+
"axes3d.anchor": validate_anchor,
1038+
"axes3d.aspect": ["auto", "equal", "equalxy", "equalxz", "equalyz"],
1039+
"axes3d.proj_type": ["persp", "ortho"],
1040+
"axes3d.box_aspect": _listify_validator(validate_float, n=3),
10211041

10221042
"axes3d.xaxis.panecolor": validate_color, # 3d background pane
10231043
"axes3d.yaxis.panecolor": validate_color, # 3d background pane

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+20-10Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Axes3D(Axes):
6464

6565
def __init__(
6666
self, fig, rect=None, *args,
67-
elev=30, azim=-60, roll=0, sharez=None, proj_type='persp',
67+
elev=30, azim=-60, roll=0, sharez=None, proj_type=None,
6868
box_aspect=None, computed_zorder=True, focal_length=None,
6969
**kwargs):
7070
"""
@@ -89,8 +89,12 @@ def __init__(
8989
scene to rotate counter-clockwise.
9090
sharez : Axes3D, optional
9191
Other Axes to share z-limits with.
92-
proj_type : {'persp', 'ortho'}
93-
The projection type, default 'persp'.
92+
proj_type : {'persp', 'ortho'}, optional
93+
The projection type, default :rc:`axes3d.proj_type`.
94+
95+
.. versionadded:: 3.8
96+
rcParam added, in earlier versions, the default is 'persp'.
97+
9498
box_aspect : 3-tuple of floats, default: None
9599
Changes the physical dimensions of the Axes3D, such that the ratio
96100
of the axis lengths in display units is x:y:z.
@@ -124,7 +128,7 @@ def __init__(
124128
self.initial_azim = azim
125129
self.initial_elev = elev
126130
self.initial_roll = roll
127-
self.set_proj_type(proj_type, focal_length)
131+
self.set_proj_type(proj_type or mpl.rcParams["axes3d.proj_type"], focal_length)
128132
self.computed_zorder = computed_zorder
129133

130134
self.xy_viewLim = Bbox.unit()
@@ -148,6 +152,12 @@ def __init__(
148152
'Use fig.add_axes(ax) instead.'
149153
)
150154

155+
if 'aspect' not in kwargs:
156+
kwargs['aspect'] = mpl.rcParams["axes3d.aspect"]
157+
if 'adjustable' not in kwargs:
158+
kwargs['adjustable'] = mpl.rcParams["axes3d.adjustable"]
159+
if 'anchor' not in kwargs:
160+
kwargs['anchor'] = mpl.rcParams["axes3d.anchor"]
151161
super().__init__(
152162
fig, rect, frameon=True, box_aspect=box_aspect, *args, **kwargs
153163
)
@@ -376,10 +386,10 @@ def set_box_aspect(self, aspect, *, zoom=1):
376386
"""
377387
Set the Axes box aspect.
378388
379-
The box aspect is the ratio of height to width in display
380-
units for each face of the box when viewed perpendicular to
381-
that face. This is not to be confused with the data aspect (see
382-
`~.Axes3D.set_aspect`). The default ratios are 4:4:3 (x:y:z).
389+
The box aspect is the ratio of height to width in display units for each face
390+
of the box when viewed perpendicular to that face. This is not to be confused
391+
with the data aspect (see `~.Axes3D.set_aspect`). The default ratios are
392+
:rc:`axes3d.box_aspect` (x, y, z).
383393
384394
To simulate having equal aspect in data space, set the box
385395
aspect to match your data range in each dimension.
@@ -391,7 +401,7 @@ def set_box_aspect(self, aspect, *, zoom=1):
391401
aspect : 3-tuple of floats or None
392402
Changes the physical dimensions of the Axes3D, such that the ratio
393403
of the axis lengths in display units is x:y:z.
394-
If None, defaults to (4, 4, 3).
404+
If None, defaults to :rc:`axes3d.box_aspect`.
395405
396406
zoom : float, default: 1
397407
Control overall size of the Axes3D in the figure. Must be > 0.
@@ -400,7 +410,7 @@ def set_box_aspect(self, aspect, *, zoom=1):
400410
raise ValueError(f'Argument zoom = {zoom} must be > 0')
401411

402412
if aspect is None:
403-
aspect = np.asarray((4, 4, 3), dtype=float)
413+
aspect = np.asarray(mpl.rcParams['axes3d.box_aspect'], dtype=float)
404414
else:
405415
aspect = np.asarray(aspect, dtype=float)
406416
_api.check_shape((3,), aspect=aspect)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.