Skip to content
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

BUG: matplotlib 3.9.0 has issue with pandas when using subplots=True on df.plot.scatter() #58851

Closed
2 of 3 tasks
Dr-Irv opened this issue May 28, 2024 · 1 comment · Fixed by #59168
Closed
2 of 3 tasks
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@Dr-Irv
Copy link
Contributor

Dr-Irv commented May 28, 2024

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 pandas as pd
df = pd.DataFrame([[5.1, 3.5, 0], [4.9, 3.0, 0], [7.0, 3.2, 1],
                   [6.4, 3.2, 1], [5.9, 3.0, 2]],
                  columns=['length', 'width', 'species'])
df.plot.scatter(x="length", y="width", subplots=True)

Issue Description

With matplotlib 3.9.0 (released 5/15/24), you get:

\lib\site-packages\pandas\plotting\_matplotlib\core.py:896: UserWarning: No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
  ax.legend(loc="best")

Expected Behavior

No warning. It doesn't appear with previous versions of matplotlib

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.9.16.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 68.2.2
pip : 22.3.1
Cython : None
pytest : 8.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.2.0
lxml.etree : 5.2.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.9.0
numba : None
numexpr : 2.10.0
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 16.1.0
pyreadstat : 1.2.7
python-calamine : None
pyxlsb : 1.0.10
s3fs : None
scipy : 1.13.0
sqlalchemy : 2.0.30
tables : 3.9.2
tabulate : 0.9.0
xarray : 2024.5.0
xlrd : 2.0.1
zstandard : 0.22.0
tzdata : 2024.1
qtpy : None
pyqt5 : None

@Dr-Irv Dr-Irv added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 28, 2024
@bnavigator
Copy link
Contributor

Also leads to test failure:

[  842s] __________________ TestDataFramePlots.test_plot_scatter_shape __________________
[  842s] [gw0] linux -- Python 3.11.9 /usr/bin/python3.11
[  842s] 
[  842s] self = <pandas.tests.plotting.frame.test_frame.TestDataFramePlots object at 0x7f63b3211590>
[  842s] 
[  842s]     def test_plot_scatter_shape(self):
[  842s]         df = DataFrame(
[  842s]             np.random.default_rng(2).standard_normal((6, 4)),
[  842s]             index=list(string.ascii_letters[:6]),
[  842s]             columns=["x", "y", "z", "four"],
[  842s]         )
[  842s]         # GH 6951
[  842s] >       axes = df.plot(x="x", y="y", kind="scatter", subplots=True)
[  842s] 
[  842s] pandas/tests/plotting/frame/test_frame.py:828: 
[  842s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[  842s] pandas/plotting/_core.py:975: in __call__
[  842s]     return plot_backend.plot(data, x=x, y=y, kind=kind, **kwargs)
[  842s] pandas/plotting/_matplotlib/__init__.py:71: in plot
[  842s]     plot_obj.generate()
[  842s] pandas/plotting/_matplotlib/core.py:503: in generate
[  842s]     self._make_legend()
[  842s] pandas/plotting/_matplotlib/core.py:896: in _make_legend
[  842s]     ax.legend(loc="best")
[  842s] /usr/lib64/python3.11/site-packages/matplotlib/axes/_axes.py:341: in legend
[  842s]     handles, labels, kwargs = mlegend._parse_legend_args([self], *args, **kwargs)
[  842s] /usr/lib64/python3.11/site-packages/matplotlib/legend.py:1364: in _parse_legend_args
[  842s]     _api.warn_external(
[  842s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[  842s] 
[  842s] message = 'No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.'
[  842s] category = None
[  842s] 
[  842s]     def warn_external(message, category=None):
[  842s]         """
[  842s]         `warnings.warn` wrapper that sets *stacklevel* to "outside Matplotlib".
[  842s]     
[  842s]         The original emitter of the warning can be obtained by patching this
[  842s]         function back to `warnings.warn`, i.e. ``_api.warn_external =
[  842s]         warnings.warn`` (or ``functools.partial(warnings.warn, stacklevel=2)``,
[  842s]         etc.).
[  842s]         """
[  842s]         frame = sys._getframe()
[  842s]         for stacklevel in itertools.count(1):
[  842s]             if frame is None:
[  842s]                 # when called in embedded context may hit frame is None
[  842s]                 break
[  842s]             if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.(?!tests\.))",
[  842s]                             # Work around sphinx-gallery not setting __name__.
[  842s]                             frame.f_globals.get("__name__", "")):
[  842s]                 break
[  842s]             frame = frame.f_back
[  842s]         # preemptively break reference cycle between locals and the frame
[  842s]         del frame
[  842s] >       warnings.warn(message, category, stacklevel)
[  842s] E       UserWarning: No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
[  842s] 

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this issue Jun 9, 2024
https://build.opensuse.org/request/show/1179390
by user mcepl + anag+factory
- Add pandas-pr58269-pyarrow16xpass.patch
  (gh#pandas-dev/pandas!58269)
- Add pandas-pr58720-xarray-dp.patch
  (gh#pandas-dev/pandas!58720), which makes pandas compatible
  with the modern xarray
- Add pandas-pr58484-matplotlib.patch
  (gh#pandas-dev/pandas!58484), which makes pandas compatible
  with the modern matplotlib
- Skip also test_plot_scatter_shape (gh#pandas-dev/pandas#58851)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants