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

Skip to content

Commit 9a62494

Browse files
Make axes3d.depthshade and axes3d.depthshade_minalpha rcparams
1 parent d5562e9 commit 9a62494

File tree

6 files changed

+58
-26
lines changed

6 files changed

+58
-26
lines changed

doc/users/next_whats_new/depthshading_improvement.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
3D depth-shading fix
22
--------------------
33

4-
Previously, a slightly buggy method of estimating the "depth" of plotted
5-
items could lead to sudden and unexpected changes in transparency as the
6-
plot orientation changed.
4+
Previously, a slightly buggy method of estimating the visual "depth" of 3D
5+
items could lead to sudden and unexpected changes in transparency as the plot
6+
orientation changed.
77

88
Now, the behavior has been made smooth and predictable. A new parameter
99
``depthshade_minalpha`` has also been added to allow users to set the minimum
10-
transparency level.
10+
transparency level. Depth-shading is an option for Patch3DCollections and
11+
Path3DCollections, including 3D scatter plots.
1112

12-
Depth-shading is an option for Patch3DCollections and Path3DCollections,
13-
including 3D scatter plots. Depth-shading is still off by default, and
14-
``depthshade=True`` must still be used to enable it.
13+
The default values for ``depthshade`` and ``depthshade_minalpha`` are now also
14+
controlled via rcParams, with values of ``True`` and ``0.3`` respectively.
1515

1616
A simple example:
1717

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@
439439
#axes3d.yaxis.panecolor: (0.90, 0.90, 0.90, 0.5) # background pane on 3D axes
440440
#axes3d.zaxis.panecolor: (0.925, 0.925, 0.925, 0.5) # background pane on 3D axes
441441

442+
#axes3d.depthshade: True # depth shade for 3D scatter plots
443+
#axes3d.depthshade_minalpha: 0.3 # minimum alpha value for depth shading
444+
442445
#axes3d.mouserotationstyle: arcball # {azel, trackball, sphere, arcball}
443446
# See also https://matplotlib.org/stable/api/toolkits/mplot3d/view_angles.html#rotation-with-mouse
444447
#axes3d.trackballsize: 0.667 # trackball diameter, in units of the Axes bbox

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ axes.spines.top : True
225225
polaraxes.grid : True # display grid on polar axes
226226
axes3d.grid : True # display grid on 3D axes
227227
axes3d.automargin : False # automatically add margin when manually setting 3D axis limits
228+
axes3d.depthshade : False # depth shade for 3D scatter plots
229+
axes3d.depthshade_minalpha : 0.3 # minimum alpha value for depth shading
228230

229231
date.autoformatter.year : %Y
230232
date.autoformatter.month : %b %Y

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,9 @@ def _convert_validator_spec(key, conv):
11331133
"axes3d.yaxis.panecolor": validate_color, # 3d background pane
11341134
"axes3d.zaxis.panecolor": validate_color, # 3d background pane
11351135

1136+
"axes3d.depthshade": validate_bool, # depth shade for 3D scatter plots
1137+
"axes3d.depthshade_minalpha": validate_float, # min alpha value for depth shading
1138+
11361139
"axes3d.mouserotationstyle": ["azel", "trackball", "sphere", "arcball"],
11371140
"axes3d.trackballsize": validate_float,
11381141
"axes3d.trackballborder": validate_float,

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from matplotlib import (
1717
_api, artist, cbook, colors as mcolors, lines, text as mtext,
18-
path as mpath)
18+
path as mpath, rcParams)
1919
from matplotlib.collections import (
2020
Collection, LineCollection, PolyCollection, PatchCollection, PathCollection)
2121
from matplotlib.patches import Patch
@@ -647,8 +647,8 @@ def __init__(
647647
*args,
648648
zs=0,
649649
zdir="z",
650-
depthshade=True,
651-
depthshade_minalpha=0.3,
650+
depthshade=None,
651+
depthshade_minalpha=None,
652652
axlim_clip=False,
653653
**kwargs
654654
):
@@ -670,6 +670,10 @@ def __init__(
670670
*depthshade_minalpha* sets the minimum alpha value applied by
671671
depth-shading.
672672
"""
673+
if depthshade is None:
674+
depthshade = rcParams['axes3d.depthshade']
675+
if depthshade_minalpha is None:
676+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
673677
self._depthshade = depthshade
674678
self._depthshade_minalpha = depthshade_minalpha
675679
super().__init__(*args, **kwargs)
@@ -681,7 +685,7 @@ def get_depthshade(self):
681685
def set_depthshade(
682686
self,
683687
depthshade,
684-
depthshade_minalpha=0.3,
688+
depthshade_minalpha=None,
685689
):
686690
"""
687691
Set whether depth shading is performed on collection members.
@@ -691,9 +695,12 @@ def set_depthshade(
691695
depthshade : bool
692696
Whether to shade the patches in order to give the appearance of
693697
depth.
694-
depthshade_minalpha : float
698+
depthshade_minalpha : float, default: None
695699
Sets the minimum alpha value used by depth-shading.
700+
If None, use the value from rcParams['axes3d.depthshade_minalpha'].
696701
"""
702+
if depthshade_minalpha is None:
703+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
697704
self._depthshade = depthshade
698705
self._depthshade_minalpha = depthshade_minalpha
699706
self.stale = True
@@ -813,8 +820,8 @@ def __init__(
813820
*args,
814821
zs=0,
815822
zdir="z",
816-
depthshade=True,
817-
depthshade_minalpha=0.3,
823+
depthshade=None,
824+
depthshade_minalpha=None,
818825
axlim_clip=False,
819826
**kwargs
820827
):
@@ -836,6 +843,10 @@ def __init__(
836843
*depthshade_minalpha* sets the minimum alpha value applied by
837844
depth-shading.
838845
"""
846+
if depthshade is None:
847+
depthshade = rcParams['axes3d.depthshade']
848+
if depthshade_minalpha is None:
849+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
839850
self._depthshade = depthshade
840851
self._depthshade_minalpha = depthshade_minalpha
841852
self._in_draw = False
@@ -919,7 +930,7 @@ def get_depthshade(self):
919930
def set_depthshade(
920931
self,
921932
depthshade,
922-
depthshade_minalpha=0.3,
933+
depthshade_minalpha=None,
923934
):
924935
"""
925936
Set whether depth shading is performed on collection members.
@@ -932,6 +943,8 @@ def set_depthshade(
932943
depthshade_minalpha : float
933944
Sets the minimum alpha value used by depth-shading.
934945
"""
946+
if depthshade_minalpha is None:
947+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
935948
self._depthshade = depthshade
936949
self._depthshade_minalpha = depthshade_minalpha
937950
self.stale = True
@@ -1029,10 +1042,10 @@ def patch_collection_2d_to_3d(
10291042
col,
10301043
zs=0,
10311044
zdir="z",
1032-
depthshade=True,
1045+
depthshade=None,
10331046
axlim_clip=False,
10341047
*args,
1035-
depthshade_minalpha=0.3
1048+
depthshade_minalpha=None,
10361049
):
10371050
"""
10381051
Convert a `.PatchCollection` into a `.Patch3DCollection` object
@@ -1049,10 +1062,12 @@ def patch_collection_2d_to_3d(
10491062
zdir : {'x', 'y', 'z'}
10501063
The axis in which to place the patches. Default: "z".
10511064
See `.get_dir_vector` for a description of the values.
1052-
depthshade
1053-
Whether to shade the patches to give a sense of depth. Default: *True*.
1054-
depthshade_minalpha
1055-
Sets the minimum alpha value used by depth-shading. Default: 0.3.
1065+
depthshade : bool, default: None
1066+
Whether to shade the patches to give a sense of depth.
1067+
If None, use the value from rcParams['axes3d.depthshade'].
1068+
depthshade_minalpha : float, default: None
1069+
Sets the minimum alpha value used by depth-shading.
1070+
If None, use the value from rcParams['axes3d.depthshade_minalpha'].
10561071
axlim_clip : bool, default: False
10571072
Whether to hide patches with a vertex outside the axes view limits.
10581073
"""
@@ -1061,6 +1076,10 @@ def patch_collection_2d_to_3d(
10611076
col._offset_zordered = None
10621077
elif isinstance(col, PatchCollection):
10631078
col.__class__ = Patch3DCollection
1079+
if depthshade is None:
1080+
depthshade = rcParams['axes3d.depthshade']
1081+
if depthshade_minalpha is None:
1082+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
10641083
col._depthshade = depthshade
10651084
col._depthshade_minalpha = depthshade_minalpha
10661085
col._in_draw = False

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,9 +2907,9 @@ def add_collection3d(self, col, zs=0, zdir='z', autolim=True, *,
29072907
@_preprocess_data(replace_names=["xs", "ys", "zs", "s",
29082908
"edgecolors", "c", "facecolor",
29092909
"facecolors", "color"])
2910-
def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
2910+
def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=None,
29112911
*args,
2912-
depthshade_minalpha=0.3,
2912+
depthshade_minalpha=None,
29132913
axlim_clip=False,
29142914
**kwargs):
29152915
"""
@@ -2943,14 +2943,15 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
29432943
- A 2D array in which the rows are RGB or RGBA.
29442944
29452945
For more details see the *c* argument of `~.axes.Axes.scatter`.
2946-
depthshade : bool, default: True
2946+
depthshade : bool, default: None
29472947
Whether to shade the scatter markers to give the appearance of
29482948
depth. Each call to ``scatter()`` will perform its depthshading
29492949
independently.
2950+
If None, use the value from rcParams['axes3d.depthshade'].
29502951
2951-
depthshade_minalpha : float, default: 0.3
2952+
depthshade_minalpha : float, default: None
29522953
The lowest alpha value applied by depth-shading.
2953-
2954+
If None, use the value from rcParams['axes3d.depthshade_minalpha'].
29542955
axlim_clip : bool, default: False
29552956
Whether to hide the scatter points outside the axes view limits.
29562957
@@ -2978,6 +2979,10 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
29782979
)
29792980
if kwargs.get("color") is not None:
29802981
kwargs['color'] = color
2982+
if depthshade is None:
2983+
depthshade = mpl.rcParams['axes3d.depthshade']
2984+
if depthshade_minalpha is None:
2985+
depthshade_minalpha = mpl.rcParams['axes3d.depthshade_minalpha']
29812986

29822987
# For xs and ys, 2D scatter() will do the copying.
29832988
if np.may_share_memory(zs_orig, zs): # Avoid unnecessary copies.

0 commit comments

Comments
 (0)