Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6758f8a

Browse files
Merge pull request matplotlib#29287 from scottshambaugh/scatter3d_shading
Fix depth shading on 3D scatterplots
2 parents 4cc7f94 + 73b3b08 commit 6758f8a

File tree

13 files changed

+264
-46
lines changed

13 files changed

+264
-46
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
3D depth-shading fix
2+
--------------------
3+
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.
7+
8+
Now, the behavior has been made smooth and predictable. A new parameter
9+
``depthshade_minalpha`` has also been added to allow users to set the minimum
10+
transparency level. Depth-shading is an option for Patch3DCollections and
11+
Path3DCollections, including 3D scatter plots.
12+
13+
The default values for ``depthshade`` and ``depthshade_minalpha`` are now also
14+
controlled via rcParams, with values of ``True`` and ``0.3`` respectively.
15+
16+
A simple example:
17+
18+
.. plot::
19+
:include-source: true
20+
:alt: A 3D scatter plot with depth-shading enabled.
21+
22+
import matplotlib.pyplot as plt
23+
24+
fig = plt.figure()
25+
ax = fig.add_subplot(projection="3d")
26+
27+
X = [i for i in range(10)]
28+
Y = [i for i in range(10)]
29+
Z = [i for i in range(10)]
30+
S = [(i + 1) * 400 for i in range(10)]
31+
32+
ax.scatter(
33+
xs=X,
34+
ys=Y,
35+
zs=Z,
36+
s=S,
37+
depthshade=True,
38+
depthshade_minalpha=0.3,
39+
)
40+
41+
plt.show()

‎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,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /