10000 Merge pull request #6439 from WeatherGod/scatter3d_color · matplotlib/matplotlib@fc654e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc654e6

Browse files
committed
Merge pull request #6439 from WeatherGod/scatter3d_color
Defer to 2D scatter() for handling of 'c'. Closes #5974.
2 parents 4f3b5cc + 8e2b7a9 commit fc654e6

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ def add_collection3d(self, col, zs=0, zdir='z'):
22092209

22102210
Axes.add_collection(self, col)
22112211

2212-
def scatter(self, xs, ys, zs=0, zdir='z', s=20, c='b', depthshade=True,
2212+
def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
22132213
*args, **kwargs):
22142214
'''
22152215
Create a scatter plot.
@@ -2233,7 +2233,9 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c='b', depthshade=True,
22332233
that *c* should not be a single numeric RGB or RGBA
22342234
sequence because that is indistinguishable from an array
22352235
of values to be colormapped. *c* can be a 2-D array in
2236-
which the rows are RGB or RGBA, however.
2236+
which the rows are RGB or RGBA, however, including the
2237+
case of a single row to specify the same color for
2238+
all points.
22372239
22382240
*depthshade*
22392241
Whether or not to shade the scatter markers to give
@@ -2262,13 +2264,15 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c='b', depthshade=True,
22622264

22632265
s = np.ma.ravel(s) # This doesn't have to match x, y in size.
22642266

2265-
cstr = cbook.is_string_like(c) or cbook.is_sequence_of_strings(c)
2266-
if not cstr:
2267-
c = np.asanyarray(c)
2268-
if c.size == xs.size:
2269-
c = np.ma.ravel(c)
2270-
2271-
xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
2267+
if c is not None:
2268+
cstr = cbook.is_string_like(c) or cbook.is_sequence_of_strings(c)
2269+
if not cstr:
2270+
c = np.asanyarray(c)
2271+
if c.size == xs.size:
2272+
c = np.ma.ravel(c)
2273+
xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
2274+
else:
2275+
xs, ys, zs, s = cbook.delete_masked_points(xs, ys, zs, s)
22722276

22732277
patches = Axes.scatter(self, xs, ys, s=s, c=c, *args, **kwargs)
22742278
if not cbook.iterable(zs):
Loading

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ def test_scatter3d():
110110
c='b', marker='^')
111111

112112

113+
@image_comparison(baseline_images=['scatter3d_color'], remove_text=True,
114+
extensions=['png'])
115+
def test_scatter3d_color():
116+
fig = plt.figure()
117+
ax = fig.add_subplot(111, projection='3d')
118+
ax.scatter(np.arange(10), np.arange(10), np.arange(10),
119+
color='r', marker='o')
120+
ax.scatter(np.arange(10, 20), np.arange(10, 20), np.arange(10, 20),
121+
color='b', marker='s')
122+
123+
113124
@image_comparison(baseline_images=['surface3d'], remove_text=True)
114125
def test_surface3d():
115126
fig = plt.figure()

0 commit comments

Comments
 (0)
0