Skip to content

Commit f0bdd3d

Browse files
committed
Add rcParams for Axes creation
1 parent 7fdf772 commit f0bdd3d

File tree

5 files changed

+62
-9
lines changed

5 files changed

+62
-9
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
11+
There are separate parameters for 3D Axes:
12+
13+
* :rc:`axes3d.adjustable`, see `.Axes.set_adjustable`
14+
* :rc:`axes3d.anchor`, see `.Axes.set_anchor`
15+
* :rc:`axes3d.aspect`, see `.Axes3D.set_aspect`
16+
* :rc:`axes3d.proj_type`, see `.Axes3D.set_proj_type`

lib/matplotlib/axes/_base.py

Lines 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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,17 @@
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+
432+
#polaraxes.grid: True # display grid on polar axes
433+
434+
#axes3d.grid: True # display grid on 3D axes
435+
#axes3d.adjustable: box # {box, adjustable}
436+
#axes3d.anchor: C # {C, E, N, S, W, NE, NW, SE, SW} or two-tuple of floats
437+
#axes3d.aspect: auto
438+
#axes3d.proj_type: persp # {persp, ortho}
430439

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

lib/matplotlib/rcsetup.py

Lines changed: 18 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,16 @@ 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
10181032

10191033
"polaraxes.grid": validate_bool, # display polar grid or not
10201034
"axes3d.grid": validate_bool, # display 3d grid
1035+
"axes3d.adjustable": ["box", "datalim"],
1036+
"axes3d.anchor": validate_anchor,
1037+
"axes3d.aspect": ["auto", "equal", "equalxy", "equalxz", "equalyz"],
1038+
"axes3d.proj_type": ["persp", "ortho"],
10211039

10221040
"axes3d.xaxis.panecolor": validate_color, # 3d background pane
10231041
"axes3d.yaxis.panecolor": validate_color, # 3d background pane

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 14 additions & 4 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
)

0 commit comments

Comments
 (0)