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

Skip to content

Commit 05db844

Browse files
committed
Add rcParams for 3D pane color
1 parent 924e210 commit 05db844

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
rcParam for 3D pane color
2+
-------------------------
3+
4+
The rcParams :rc:`axes3d.panecolorx`, :rc:`axes3d.panecolory`,
5+
:rc:`axes3d.panecolorz` 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+
.. code-block:: python
11+
12+
import matplotlib.pyplot as plt
13+
with plt.rc_context({'axes3d.panecolorx': (0.9, 0.0, 0.0, 0.5),
14+
'axes3d.panecolory': (0.7, 0.0, 0.0, 0.5),
15+
'axes3d.panecolorz': (0.8, 0.0, 0.0, 0.5)}):
16+
fig = plt.figure()
17+
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.panecolorx: (0.95, 0.95, 0.95, 0.5) # background pane on 3D axes
431+
#axes3d.panecolory: (0.90, 0.90, 0.90, 0.5) # background pane on 3D axes
432+
#axes3d.panecolorz: (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.panecolorx": validate_color, # 3d background pane
1024+
"axes3d.panecolory": validate_color, # 3d background pane
1025+
"axes3d.panecolorz": 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: 9 additions & 8 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,9 +94,14 @@ 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.panecolor{name}'],
101+
})
102+
100103
if mpl.rcParams['_internal.classic_mode']:
101104
self._axinfo.update({
102-
'label': {'va': 'center', 'ha': 'center'},
103105
'tick': {
104106
'inward_factor': 0.2,
105107
'outward_factor': 0.1,
@@ -117,7 +119,6 @@ def __init__(self, *args, **kwargs):
117119
})
118120
else:
119121
self._axinfo.update({
120-
'label': {'va': 'center', 'ha': 'center'},
121122
'tick': {
122123
'inward_factor': 0.2,
123124
'outward_factor': 0.1,

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,3 +2034,14 @@ def test_arc_pathpatch():
20342034
angle=20, theta1=10, theta2=130)
20352035
ax.add_patch(a)
20362036
art3d.pathpatch_2d_to_3d(a, z=0, zdir='z')
2037+
2038+
2039+
@image_comparison(baseline_images=['panecolor_rcparams.png'],
2040+
remove_text=True,
2041+
style='mpl20')
2042+
def test_panecolor_rcparams():
2043+
with plt.rc_context({'axes3d.panecolorx': 'r',
2044+
'axes3d.panecolory': 'g',
2045+
'axes3d.panecolorz': 'b'}):
2046+
fig = plt.figure(figsize=(1, 1))
2047+
fig.add_subplot(projection='3d')

0 commit comments

Comments
 (0)