BUG: can't pass Colormap
instance when plotting if using matplotlib >= 3.6 · Issue #49374 · pandas-dev/pandas (original) (raw)
Pandas version checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import matplotlib as mpl import pandas as pd
df = pd.DataFrame({"x": [0], "y": [0]})
df.plot.scatter(x="x", y="y", colormap=mpl.cm.get_cmap("Spectral"))
Issue Description
See more info in NCAR/MELODIES-MONET#135 where I first ran into this.
Expected Behavior
Seems like replacing cmap = mpl.colormaps[self.colormap]
with cmap = mpl.colormaps.get(self.colormap)
will resolve this. This is 2nd option mentioned in the (doc) deprecation message:
Use ``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap(obj)`` instead.
Installed Versions
INSTALLED VERSIONS
commit : 91111fd
python : 3.9.13.final.0
python-bits : 64
OS : Linux
OS-release : 4.18.0-348.7.1.el8_5.x86_64
Version : #1 SMP Wed Dec 22 13:25:12 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.5.1
numpy : 1.23.4
pytz : 2022.5
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.5.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli :
fastparquet : 0.8.3
fsspec : 2022.10.0
gcsfs : None
matplotlib : 3.6.1
numba : 0.56.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : 2022.10.0
scipy : 1.9.3
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : 2022.10.0
xlrd : None
xlwt : None
zstandard : None
tzdata : None