Skip to content

Fix issue with get_edgecolor and get_facecolor in 3D plots #23562

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
Aug 19, 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
10 changes: 10 additions & 0 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,19 @@ def set_alpha(self, alpha):
self.stale = True

def get_facecolor(self):
# docstring inherited
# self._facecolors2d is not initialized until do_3d_projection
if not hasattr(self, '_facecolors2d'):
self.axes.M = self.axes.get_proj()
self.do_3d_projection()
return self._facecolors2d

def get_edgecolor(self):
# docstring inherited
# self._edgecolors2d is not initialized until do_3d_projection
if not hasattr(self, '_edgecolors2d'):
self.axes.M = self.axes.get_proj()
self.do_3d_projection()
return self._edgecolors2d


Expand Down
22 changes: 22 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,28 @@ def test_scatter_spiral():
fig.canvas.draw()


def test_Poly3DCollection_get_facecolor():
# Smoke test to see that get_facecolor does not raise
# See GH#4067
y, x = np.ogrid[1:10:100j, 1:10:100j]
z2 = np.cos(x) ** 3 - np.sin(y) ** 2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
r = ax.plot_surface(x, y, z2, cmap='hot')
r.get_facecolor()


def test_Poly3DCollection_get_edgecolor():
# Smoke test to see that get_edgecolor does not raise
# See GH#4067
y, x = np.ogrid[1:10:100j, 1:10:100j]
z2 = np.cos(x) ** 3 - np.sin(y) ** 2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
r = ax.plot_surface(x, y, z2, cmap='hot')
r.get_edgecolor()


@pytest.mark.parametrize(
"vertical_axis, proj_expected, axis_lines_expected, tickdirs_expected",
[
Expand Down