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

Appearance settings

bug fix - set_facecolors not working for 3D scatter #10489

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

Closed
Closed
Show file tree
Hide file tree
Changes from 6 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
55 changes: 55 additions & 0 deletions 55 lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import six
from six.moves import map, zip, reduce

import types
from collections import defaultdict
import math
import warnings
Expand Down Expand Up @@ -2364,6 +2365,60 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir,
depthshade=depthshade)

def set_facecolor3d(self, c):
"""
Set the facecolor(s) of the collection. *c* can be a
matplotlib color spec (all patches have same color), or a
sequence of specs; if it is a sequence the patches will
cycle through the sequence.

If *c* is 'none', the patch will not be filled.

ACCEPTS: matplotlib color spec or sequence of specs
"""
self.set_facecolor2d(c)

c = self.get_facecolor().copy() # new color
length_old = self._facecolor3d.shape[0]
length_new = c.shape[0]
# reset alpha value to original
if (length_new > length_old):
c[:, 3] = self._facecolor3d[0, 3]
elif (length_new == length_old):
c[:, 3] = self._facecolor3d[:, 3]
self._facecolor3d = c

def set_edgecolor3d(self, c):
"""
Set the edgecolor(s) of the collection. *c* can be a
matplotlib color spec (all patches have same color), or a
sequence of specs; if it is a sequence the patches will
cycle through the sequence.

If *c* is 'face', the edge color will always be the same as
the face color. If it is 'none', the patch boundary will not
be drawn.

ACCEPTS: matplotlib color spec or sequence of specs
"""
self.set_edgecolor2d(c)

c = self.get_edgecolor().copy() # new color
length_old = self._edgecolor3d.shape[0]
length_new = c.shape[0]

# reset alpha value to original
if (length_new > length_old):
c[:, 3] = self._edgecolor3d[0, 3]
elif (length_new == length_old):
c[:, 3] = self._edgecolor3d[:, 3]
self._edgecolor3d = c

patches.set_facecolor2d = patches.set_facecolor
patches.set_facecolor = types.MethodType(set_facecolor3d, patches)
patches.set_edgecolor2d = patches.set_edgecolor
patches.set_edgecolor = types.MethodType(set_edgecolor3d, patches)

if self._zmargin < 0.05 and xs.size > 0:
self.set_zmargin(0.05)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions 20 lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ def test_scatter3d_color():
color='b', marker='s')


@image_comparison(baseline_images=['scatter3d_change_color'], remove_text=True,
style='mpl20', extensions=['png'])
def test_scatter3d_change_color():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.xaxis.set_major_formatter(plt.NullFormatter())
ax.yaxis.set_major_formatter(plt.NullFormatter())
ax.zaxis.set_major_formatter(plt.NullFormatter())
sca1 = ax.scatter(0, 0, 0, color='r', marker='o')
sca2 = ax.scatter(np.arange(1, 3), np.arange(1, 3), np.arange(1, 3),
color=['orange', 'green'], marker='^')
sca3 = ax.scatter(np.arange(3, 6), np.arange(3, 6), np.arange(3, 6),
color='#FF0000', marker='s')

sca1.set_color("green")
sca2.set_facecolor([0, 1, 1])
sca2.set_edgecolor('face')
sca3.set_facecolor(["white", "#ABCDEF", [0, 0, 0]])


@image_comparison(baseline_images=['surface3d'], remove_text=True)
def test_surface3d():
fig = plt.figure()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.