Skip to content

Using scatter with unfilled marker raises matplotlib UserWarning #7313

Closed
@derhintze

Description

@derhintze

What is your issue?

If plotting a scatter plot with an unfilled marker, matplotlib raises a UserWarning. Consider this MWE:

import warnings

import numpy as np
import xarray as xr

warnings.filterwarnings("error")

ds = xr.Dataset({"a": ("dim", np.arange(3, 10))}, {"dim": np.arange(7)})
ds.plot.scatter(x="dim", y="a", marker="x")

Running this with matplotlib 3.6.2 yields:

Traceback (most recent call last):
  File "/my/path/test.py", line 9, in <module>
    ds.plot.scatter(x="dim", y="a", marker="x")
  File "/my/path/.venv/lib/python3.9/site-packages/xarray/plot/accessor.py", line 1071, in scatter
    return dataset_plot.scatter(self._ds, *args, **kwargs)
  File "/my/path/.venv/lib/python3.9/site-packages/xarray/plot/dataset_plot.py", line 916, in scatter
    return da.plot.scatter(*locals_.pop("args", ()), **locals_)
  File "/my/path/.venv/lib/python3.9/site-packages/xarray/plot/accessor.py", line 305, in scatter
    return dataarray_plot.scatter(self._da, *args, **kwargs)
  File "/my/path/.venv/lib/python3.9/site-packages/xarray/plot/dataarray_plot.py", line 1002, in newplotfunc
    primitive = plotfunc(
  File "/my/path/.venv/lib/python3.9/site-packages/xarray/plot/dataarray_plot.py", line 1277, in scatter
    primitive = ax.scatter(*[p.to_numpy().ravel() for p in plts], **kwargs)
  File "/my/path/.venv/lib/python3.9/site-packages/matplotlib/__init__.py", line 1423, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/my/path/.venv/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 4571, in scatter
    _api.warn_external(
  File "/my/path/.venv/lib/python3.9/site-packages/matplotlib/_api/__init__.py", line 363, in warn_external
    warnings.warn(message, category, stacklevel)
UserWarning: You passed a edgecolor/edgecolors ('w') for an unfilled marker ('x').  Matplotlib is ignoring the edgecolor in favor of the facecolor.  This behavior may change in the future.

Environment:

INSTALLED VERSIONS
------------------
commit: None
python: 3.9.10 (main, Mar 15 2022, 15:56:56) 
[GCC 7.5.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-1160.49.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.2
libnetcdf: 4.9.0

xarray: 2022.11.0
pandas: 1.5.1
numpy: 1.23.5
scipy: 1.9.3
netCDF4: 1.6.2
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.6.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.6.2
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 65.6.0
pip: 22.3.1
conda: None
pytest: 7.2.0
IPython: 8.6.0
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions