Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b03a5d7

Browse files
committed
Add rcParams for Axes creation
1 parent 61ed3f4 commit b03a5d7

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

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
@@ -424,8 +424,17 @@
424424
#axes.autolimit_mode: data # If "data", use axes.xmargin and axes.ymargin as is.
425425
# If "round_numbers", after application of margins, axis
426426
# limits are further expanded to the nearest "round" number.
427-
#polaraxes.grid: True # display grid on polar axes
428-
#axes3d.grid: True # display grid on 3D axes
427+
#axes.adjustable: box # {box, adjustable}
428+
#axes.anchor: C # {C, E, N, S, W, NE, NW, SE, SW} or two-tuple of floats
429+
#axes.aspect: auto # {equal, auto} or a number
430+
431+
#polaraxes.grid: True # display grid on polar axes
432+
433+
#axes3d.grid: True # display grid on 3D axes
434+
#axes3d.adjustable: box # {box, adjustable}
435+
#axes3d.anchor: C # {C, E, N, S, W, NE, NW, SE, SW} or two-tuple of floats
436+
#axes3d.aspect: auto
437+
#axes3d.proj_type: persp # {persp, ortho}
429438

430439
#axes3d.xaxis.panecolor: (0.95, 0.95, 0.95, 0.5) # background pane on 3D axes
431440
#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
@@ -1014,9 +1025,16 @@ def _convert_validator_spec(key, conv):
10141025
"axes.xmargin": _range_validators["0 <= x <= 1"], # margin added to xaxis
10151026
"axes.ymargin": _range_validators["0 <= x <= 1"], # margin added to yaxis
10161027
'axes.zmargin': _range_validators["0 <= x <= 1"], # margin added to zaxis
1028+
"axes.adjustable": ["box", "datalim"],
1029+
"axes.anchor": validate_anchor,
1030+
"axes.aspect": validate_aspect, # equal, auto, a number
10171031

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

10211039
"axes3d.xaxis.panecolor": validate_color, # 3d background pane
10221040
"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)