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

Skip to content

Add rcParams for 3D pane color #24031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/users/next_whats_new/3d_pane_color_rcparams.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rcParam for 3D pane color
-------------------------

The rcParams :rc:`axes3d.xaxis.panecolor`, :rc:`axes3d.yaxis.panecolor`,
:rc:`axes3d.zaxis.panecolor` can be used to change the color of the background
panes in 3D plots. Note that it is often beneficial to give them slightly
different shades to obtain a "3D effect" and to make them slightly transparent
(alpha < 1).

.. plot::
:include-source: true

import matplotlib.pyplot as plt
with plt.rc_context({'axes3d.xaxis.panecolor': (0.9, 0.0, 0.0, 0.5),
'axes3d.yaxis.panecolor': (0.7, 0.0, 0.0, 0.5),
'axes3d.zaxis.panecolor': (0.8, 0.0, 0.0, 0.5)}):
fig = plt.figure()
fig.add_subplot(projection='3d')
3 changes: 3 additions & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@
#polaraxes.grid: True # display grid on polar axes
#axes3d.grid: True # display grid on 3D axes

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

## ***************************************************************************
## * AXIS *
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,10 @@ def _convert_validator_spec(key, conv):
"polaraxes.grid": validate_bool, # display polar grid or not
"axes3d.grid": validate_bool, # display 3d grid

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

# scatter props
"scatter.marker": validate_string,
"scatter.edgecolors": validate_string,
Expand Down
57 changes: 29 additions & 28 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,9 @@ class Axis(maxis.XAxis):

# Some properties for the axes
_AXINFO = {
'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2),
'color': (0.95, 0.95, 0.95, 0.5)},
'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2),
'color': (0.90, 0.90, 0.90, 0.5)},
'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1),
'color': (0.925, 0.925, 0.925, 0.5)},
'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2)},
'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2)},
'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1)},
}

def _old_init(self, adir, v_intervalx, d_intervalx, axes, *args,
Expand Down Expand Up @@ -97,39 +94,33 @@ def __init__(self, *args, **kwargs):
# This is a temporary member variable.
# Do not depend on this existing in future releases!
self._axinfo = self._AXINFO[name].copy()
# Common parts
self._axinfo.update({
'label': {'va': 'center', 'ha': 'center'},
'color': mpl.rcParams[f'axes3d.{name}axis.panecolor'],
'tick': {
'inward_factor': 0.2,
'outward_factor': 0.1,
},
})

if mpl.rcParams['_internal.classic_mode']:
self._axinfo.update({
'label': {'va': 'center', 'ha': 'center'},
'tick': {
'inward_factor': 0.2,
'outward_factor': 0.1,
'linewidth': {
True: mpl.rcParams['lines.linewidth'], # major
False: mpl.rcParams['lines.linewidth'], # minor
}
},
'axisline': {'linewidth': 0.75, 'color': (0, 0, 0, 1)},
'grid': {
'color': (0.9, 0.9, 0.9, 1),
'linewidth': 1.0,
'linestyle': '-',
},
})
self._axinfo['tick'].update({
'linewidth': {
True: mpl.rcParams['lines.linewidth'], # major
False: mpl.rcParams['lines.linewidth'], # minor
}
})
else:
self._axinfo.update({
'label': {'va': 'center', 'ha': 'center'},
'tick': {
'inward_factor': 0.2,
'outward_factor': 0.1,
'linewidth': {
True: ( # major
mpl.rcParams['xtick.major.width'] if name in 'xz'
else mpl.rcParams['ytick.major.width']),
False: ( # minor
mpl.rcParams['xtick.minor.width'] if name in 'xz'
else mpl.rcParams['ytick.minor.width']),
}
},
'axisline': {
'linewidth': mpl.rcParams['axes.linewidth'],
'color': mpl.rcParams['axes.edgecolor'],
Expand All @@ -140,6 +131,16 @@ def __init__(self, *args, **kwargs):
'linestyle': mpl.rcParams['grid.linestyle'],
},
})
self._axinfo['tick'].update({
'linewidth': {
True: ( # major
mpl.rcParams['xtick.major.width'] if name in 'xz'
else mpl.rcParams['ytick.major.width']),
False: ( # minor
mpl.rcParams['xtick.minor.width'] if name in 'xz'
else mpl.rcParams['ytick.minor.width']),
}
})

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

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2113,3 +2113,14 @@ def test_arc_pathpatch():
angle=20, theta1=10, theta2=130)
ax.add_patch(a)
art3d.pathpatch_2d_to_3d(a, z=0, zdir='z')


@image_comparison(baseline_images=['panecolor_rcparams.png'],
remove_text=True,
style='mpl20')
def test_panecolor_rcparams():
with plt.rc_context({'axes3d.xaxis.panecolor': 'r',
'axes3d.yaxis.panecolor': 'g',
'axes3d.zaxis.panecolor': 'b'}):
fig = plt.figure(figsize=(1, 1))
fig.add_subplot(projection='3d')