Skip to content

Commit e3f00de

Browse files
committed
solve conversation
1 parent bc0bb49 commit e3f00de

File tree

3 files changed

+94
-138
lines changed

3 files changed

+94
-138
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,11 +2199,11 @@ def plot_surface(self, X, Y, Z, *, norm=None, vmin=None,
21992199
Bounds for the normalization.
22002200
22012201
shade : bool or "auto", default: "auto"
2202-
Whether to shade the facecolors. "auto" will shade only if the facecolor is uniform,
2203-
i.e. neither *cmap* nor *facecolors* is given.
2202+
Whether to shade the facecolors. "auto" will shade only if the facecolor
2203+
is uniform, i.e. neither *cmap* nor *facecolors* is given.
22042204
2205-
Furthermore, shading is generally not compatible with colormapping and
2206-
``shade=True, cmap=...`` will raise an error.
2205+
Furthermore, shading is generally not compatible with colormapping
2206+
and ``shade=True, cmap=...`` will raise an error.
22072207
22082208
lightsource : `~matplotlib.colors.LightSource`, optional
22092209
The lightsource to use when *shade* is True.
@@ -2257,8 +2257,12 @@ def plot_surface(self, X, Y, Z, *, norm=None, vmin=None,
22572257
shade = kwargs.pop('shade', 'auto')
22582258
if shade == "auto":
22592259
shade = cmap is None and fcolors is None
2260-
elif shade is None:
2261-
raise ValueError("shade cannot be None.")
2260+
# Remove the None check as it doesn't seem to be needed
2261+
2262+
# Raise error if shade=True and cmap is provided as documented
2263+
if shade is True and cmap is not None:
2264+
raise ValueError("Shading is not compatible with colormapping. "
2265+
"Set shade=False or do not provide a cmap.")
22622266

22632267
colset = [] # the sampled facecolor
22642268
if (rows - 1) % rstride == 0 and \

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,3 +2689,87 @@ def test_ndarray_color_kwargs_value_error():
26892689
ax = fig.add_subplot(111, projection='3d')
26902690
ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1]))
26912691
fig.canvas.draw()
2692+
2693+
2694+
@check_figures_equal()
2695+
def test_plot_surface_shade_auto_with_facecolors(fig_test, fig_ref):
2696+
"""Test that plot_surface with facecolors uses shade=False by default."""
2697+
X = np.linspace(0, 1, 5)
2698+
Y = np.linspace(0, 1, 5)
2699+
X_mesh, Y_mesh = np.meshgrid(X, Y)
2700+
Z = X_mesh + Y_mesh
2701+
colors = cm.viridis(X_mesh)
2702+
2703+
# Test with facecolors (should have shade=False by default)
2704+
ax_test = fig_test.add_subplot(projection='3d')
2705+
ax_test.plot_surface(X_mesh, Y_mesh, Z, facecolors=colors)
2706+
2707+
# Reference with explicit shade=False
2708+
ax_ref = fig_ref.add_subplot(projection='3d')
2709+
ax_ref.plot_surface(X_mesh, Y_mesh, Z, facecolors=colors, shade=False)
2710+
2711+
2712+
@check_figures_equal()
2713+
def test_plot_surface_shade_auto_without_facecolors(fig_test, fig_ref):
2714+
"""Test that plot_surface without facecolors uses shade=True by default."""
2715+
X = np.linspace(0, 1, 5)
2716+
Y = np.linspace(0, 1, 5)
2717+
X_mesh, Y_mesh = np.meshgrid(X, Y)
2718+
Z = X_mesh + Y_mesh
2719+
2720+
# Test without facecolors (should have shade=True by default)
2721+
ax_test = fig_test.add_subplot(projection='3d')
2722+
ax_test.plot_surface(X_mesh, Y_mesh, Z)
2723+
2724+
# Reference with explicit shade=True
2725+
ax_ref = fig_ref.add_subplot(projection='3d')
2726+
ax_ref.plot_surface(X_mesh, Y_mesh, Z, shade=True)
2727+
2728+
2729+
@check_figures_equal()
2730+
def test_plot_surface_shade_auto_with_cmap(fig_test, fig_ref):
2731+
"""Test that plot_surface with cmap uses shade=False by default."""
2732+
X = np.linspace(0, 1, 5)
2733+
Y = np.linspace(0, 1, 5)
2734+
X_mesh, Y_mesh = np.meshgrid(X, Y)
2735+
Z = X_mesh + Y_mesh
2736+
2737+
# Test with cmap (should have shade=False by default)
2738+
ax_test = fig_test.add_subplot(projection='3d')
2739+
ax_test.plot_surface(X_mesh, Y_mesh, Z, cmap=cm.viridis)
2740+
2741+
# Reference with explicit shade=False
2742+
ax_ref = fig_ref.add_subplot(projection='3d')
2743+
ax_ref.plot_surface(X_mesh, Y_mesh, Z, cmap=cm.viridis, shade=False)
2744+
2745+
2746+
@check_figures_equal()
2747+
def test_plot_surface_shade_override_with_facecolors(fig_test, fig_ref):
2748+
"""Test that explicit shade parameter overrides auto behavior with facecolors."""
2749+
X = np.linspace(0, 1, 5)
2750+
Y = np.linspace(0, 1, 5)
2751+
X_mesh, Y_mesh = np.meshgrid(X, Y)
2752+
Z = X_mesh + Y_mesh
2753+
colors = cm.viridis(X_mesh)
2754+
2755+
# Test with explicit shade=True (overrides auto behavior)
2756+
ax_test = fig_test.add_subplot(projection='3d')
2757+
ax_test.plot_surface(X_mesh, Y_mesh, Z, facecolors=colors, shade=True)
2758+
2759+
# Reference with explicit shade=True
2760+
ax_ref = fig_ref.add_subplot(projection='3d')
2761+
ax_ref.plot_surface(X_mesh, Y_mesh, Z, facecolors=colors, shade=True)
2762+
2763+
2764+
def test_plot_surface_shade_with_cmap_raises():
2765+
"""Test that shade=True with cmap raises an error."""
2766+
X = np.linspace(0, 1, 5)
2767+
Y = np.linspace(0, 1, 5)
2768+
X_mesh, Y_mesh = np.meshgrid(X, Y)
2769+
Z = X_mesh + Y_mesh
2770+
2771+
fig = plt.figure()
2772+
ax = fig.add_subplot(projection='3d')
2773+
2774+
with pytest.raises(ValueError, match="Shading is not compatible with colormapping"):
2775+
ax.plot_surface(X_mesh, Y_mesh, Z, cmap=cm.viridis, shade=True)

lib/mpl_toolkits/mplot3d/tests/test_plot_surface_shade.py

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)