Skip to content
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixed regressions
~~~~~~~~~~~~~~~~~
- Fixed Regression in :meth:`DataFrame.loc` when setting values as a :class:`DataFrame` with all ``True`` indexer (:issue:`48701`)
- Regression in :func:`.read_csv` causing an ``EmptyDataError`` when using an UTF-8 file handle that was already read from (:issue:`48646`)
- Fixed regression in :meth:`DataFrame.plot` ignoring invalid ``colormap`` for ``kind="scatter"`` (:issue:`48726`)
- Fixed performance regression in :func:`factorize` when ``na_sentinel`` is not ``None`` and ``sort=False`` (:issue:`48620`)
-

Expand Down
20 changes: 13 additions & 7 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,16 +1231,22 @@ def _make_plot(self):
else:
c_values = c

# cmap is only used if c_values are integers, otherwise UserWarning
if is_integer_dtype(c_values):
# pandas uses colormap, matplotlib uses cmap.
cmap = self.colormap or "Greys"
if self.colormap is not None:
if mpl_ge_3_6_0():
cmap = mpl.colormaps[cmap]
cmap = mpl.colormaps[self.colormap]
else:
cmap = self.plt.cm.get_cmap(cmap)
cmap = self.plt.cm.get_cmap(self.colormap)
else:
cmap = None
# cmap is only used if c_values are integers, otherwise UserWarning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phofl fyi I think this caused a new warning in test_scatter_with_c_column_name_with_colors

pandas/tests/plotting/frame/test_frame_color.py::TestDataFrameColor::test_scatter_with_c_column_name_with_colors[c-Greys]
pandas/tests/plotting/frame/test_frame_color.py::TestDataFrameColor::test_scatter_with_c_column_name_with_colors[color-Greys]
  /Users/runner/work/pandas/pandas/pandas/plotting/_matplotlib/core.py:1270: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
    scatter = ax.scatter(

Does that mean we should expect the UserWarning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, had a different version installed locally.

if is_integer_dtype(c_values):
# pandas uses colormap, matplotlib uses cmap.
cmap = "Greys"
if mpl_ge_3_6_0():
cmap = mpl.colormaps[cmap]
else:
cmap = self.plt.cm.get_cmap(cmap)
else:
cmap = None

if color_by_categorical:
from matplotlib import colors
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,12 @@ def _check_errorbar_color(containers, expected, has_err="has_xerr"):
self._check_has_errorbars(ax, xerr=0, yerr=1)
_check_errorbar_color(ax.containers, "green", has_err="has_yerr")

def test_scatter_unknown_colormap(self):
# GH#48726
df = DataFrame({"a": [1, 2, 3], "b": 4})
with pytest.raises((ValueError, KeyError), match="'unknown' is not a"):
df.plot(x="a", y="b", colormap="unknown", kind="scatter")

def test_sharex_and_ax(self):
# https://github.com/pandas-dev/pandas/issues/9737 using gridspec,
# the axis in fig.get_axis() are sorted differently than pandas
Expand Down