Skip to content

Commit 106b15a

Browse files
committed
COMPAT/BUG: color handling in scatter
MPL 1.5 seems to have changed the behavior of ax.scatter(x, y, c='green', color=['blue']) Since this doesn't really make sense anyway(?) I'm changing our code so that the user doesn't get into that state.
1 parent 54f20cf commit 106b15a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pandas/tests/test_graphics.py

+13
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,19 @@ def test_plot_scatter_with_c(self):
20622062
float_array = np.array([0.0, 1.0])
20632063
df.plot.scatter(x='A', y='B', c=float_array, cmap='spring')
20642064

2065+
def test_scatter_colors(self):
2066+
df = DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3], 'c': [1, 2, 3]})
2067+
with tm.assertRaises(TypeError):
2068+
df.plot.scatter(x='a', y='b', c='c', color='green')
2069+
2070+
ax = df.plot.scatter(x='a', y='b', c='c')
2071+
tm.assert_numpy_array_equal(ax.collections[0].get_facecolor()[0],
2072+
(0, 0, 1, 1))
2073+
2074+
ax = df.plot.scatter(x='a', y='b', color='white')
2075+
tm.assert_numpy_array_equal(ax.collections[0].get_facecolor()[0],
2076+
(1, 1, 1, 1))
2077+
20652078
@slow
20662079
def test_plot_bar(self):
20672080
df = DataFrame(randn(6, 4),

pandas/tools/plotting.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1535,9 +1535,13 @@ def _make_plot(self):
15351535
# pandas uses colormap, matplotlib uses cmap.
15361536
cmap = self.colormap or 'Greys'
15371537
cmap = self.plt.cm.get_cmap(cmap)
1538-
1539-
if c is None:
1538+
color = self.kwds.pop("color", None)
1539+
if c is not None and color is not None:
1540+
raise TypeError('Specify exactly one of `c` and `color`')
1541+
elif c is None and color is None:
15401542
c_values = self.plt.rcParams['patch.facecolor']
1543+
elif color is not None:
1544+
c_values = color
15411545
elif c_is_column:
15421546
c_values = self.data[c].values
15431547
else:

0 commit comments

Comments
 (0)