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

Skip to content

Commit 394748d

Browse files
authored
Merge pull request #24031 from oscargus/panecolorrcparams
Add rcParams for 3D pane color
2 parents 0c3ba6d + 5dc7338 commit 394748d

File tree

6 files changed

+65
-28
lines changed

6 files changed

+65
-28
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
rcParam for 3D pane color
2+
-------------------------
3+
4+
The rcParams :rc:`axes3d.xaxis.panecolor`, :rc:`axes3d.yaxis.panecolor`,
5+
:rc:`axes3d.zaxis.panecolor` can be used to change the color of the background
6+
panes in 3D plots. Note that it is often beneficial to give them slightly
7+
different shades to obtain a "3D effect" and to make them slightly transparent
8+
(alpha < 1).
9+
10+
.. plot::
11+
:include-source: true
12+
13+
import matplotlib.pyplot as plt
14+
with plt.rc_context({'axes3d.xaxis.panecolor': (0.9, 0.0, 0.0, 0.5),
15+
'axes3d.yaxis.panecolor': (0.7, 0.0, 0.0, 0.5),
16+
'axes3d.zaxis.panecolor': (0.8, 0.0, 0.0, 0.5)}):
17+
fig = plt.figure()
18+
fig.add_subplot(projection='3d')

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@
427427
#polaraxes.grid: True # display grid on polar axes
428428
#axes3d.grid: True # display grid on 3D axes
429429

430+
#axes3d.xaxis.panecolor: (0.95, 0.95, 0.95, 0.5) # background pane on 3D axes
431+
#axes3d.yaxis.panecolor: (0.90, 0.90, 0.90, 0.5) # background pane on 3D axes
432+
#axes3d.zaxis.panecolor: (0.925, 0.925, 0.925, 0.5) # background pane on 3D axes
430433

431434
## ***************************************************************************
432435
## * AXIS *

lib/matplotlib/rcsetup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,10 @@ def _convert_validator_spec(key, conv):
10201020
"polaraxes.grid": validate_bool, # display polar grid or not
10211021
"axes3d.grid": validate_bool, # display 3d grid
10221022

1023+
"axes3d.xaxis.panecolor": validate_color, # 3d background pane
1024+
"axes3d.yaxis.panecolor": validate_color, # 3d background pane
1025+
"axes3d.zaxis.panecolor": validate_color, # 3d background pane
1026+
10231027
# scatter props
10241028
"scatter.marker": validate_string,
10251029
"scatter.edgecolors": validate_string,

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ class Axis(maxis.XAxis):
6161

6262
# Some properties for the axes
6363
_AXINFO = {
64-
'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2),
65-
'color': (0.95, 0.95, 0.95, 0.5)},
66-
'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2),
67-
'color': (0.90, 0.90, 0.90, 0.5)},
68-
'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1),
69-
'color': (0.925, 0.925, 0.925, 0.5)},
64+
'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2)},
65+
'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2)},
66+
'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1)},
7067
}
7168

7269
def _old_init(self, adir, v_intervalx, d_intervalx, axes, *args,
@@ -97,39 +94,33 @@ def __init__(self, *args, **kwargs):
9794
# This is a temporary member variable.
9895
# Do not depend on this existing in future releases!
9996
self._axinfo = self._AXINFO[name].copy()
97+
# Common parts
98+
self._axinfo.update({
99+
'label': {'va': 'center', 'ha': 'center'},
100+
'color': mpl.rcParams[f'axes3d.{name}axis.panecolor'],
101+
'tick': {
102+
'inward_factor': 0.2,
103+
'outward_factor': 0.1,
104+
},
105+
})
106+
100107
if mpl.rcParams['_internal.classic_mode']:
101108
self._axinfo.update({
102-
'label': {'va': 'center', 'ha': 'center'},
103-
'tick': {
104-
'inward_factor': 0.2,
105-
'outward_factor': 0.1,
106-
'linewidth': {
107-
True: mpl.rcParams['lines.linewidth'], # major
108-
False: mpl.rcParams['lines.linewidth'], # minor
109-
}
110-
},
111109
'axisline': {'linewidth': 0.75, 'color': (0, 0, 0, 1)},
112110
'grid': {
113111
'color': (0.9, 0.9, 0.9, 1),
114112
'linewidth': 1.0,
115113
'linestyle': '-',
116114
},
117115
})
116+
self._axinfo['tick'].update({
117+
'linewidth': {
118+
True: mpl.rcParams['lines.linewidth'], # major
119+
False: mpl.rcParams['lines.linewidth'], # minor
120+
}
121+
})
118122
else:
119123
self._axinfo.update({
120-
'label': {'va': 'center', 'ha': 'center'},
121-
'tick': {
122-
'inward_factor': 0.2,
123-
'outward_factor': 0.1,
124-
'linewidth': {
125-
True: ( # major
126-
mpl.rcParams['xtick.major.width'] if name in 'xz'
127-
else mpl.rcParams['ytick.major.width']),
128-
False: ( # minor
129-
mpl.rcParams['xtick.minor.width'] if name in 'xz'
130-
else mpl.rcParams['ytick.minor.width']),
131-
}
132-
},
133124
'axisline': {
134125
'linewidth': mpl.rcParams['axes.linewidth'],
135126
'color': mpl.rcParams['axes.edgecolor'],
@@ -140,6 +131,16 @@ def __init__(self, *args, **kwargs):
140131
'linestyle': mpl.rcParams['grid.linestyle'],
141132
},
142133
})
134+
self._axinfo['tick'].update({
135+
'linewidth': {
136+
True: ( # major
137+
mpl.rcParams['xtick.major.width'] if name in 'xz'
138+
else mpl.rcParams['ytick.major.width']),
139+
False: ( # minor
140+
mpl.rcParams['xtick.minor.width'] if name in 'xz'
141+
else mpl.rcParams['ytick.minor.width']),
142+
}
143+
})
143144

144145
super().__init__(axes, *args, **kwargs)
145146

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,3 +2113,14 @@ def test_arc_pathpatch():
21132113
angle=20, theta1=10, theta2=130)
21142114
ax.add_patch(a)
21152115
art3d.pathpatch_2d_to_3d(a, z=0, zdir='z')
2116+
2117+
2118+
@image_comparison(baseline_images=['panecolor_rcparams.png'],
2119+
remove_text=True,
2120+
style='mpl20')
2121+
def test_panecolor_rcparams():
2122+
with plt.rc_context({'axes3d.xaxis.panecolor': 'r',
2123+
'axes3d.yaxis.panecolor': 'g',
2124+
'axes3d.zaxis.panecolor': 'b'}):
2125+
fig = plt.figure(figsize=(1, 1))
2126+
fig.add_subplot(projection='3d')

0 commit comments

Comments
 (0)