-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
plot.scatter(hue_style="discrete")
does nothing
#7907
Comments
Possibly related: #7268 |
I remember at some point there was handling for The idea now is to just choose if you want a legend or a colorbar. You'll get something useful either way. You'll even get hue and sizes in 1 legend if you want that, something that was not previously possible. Now numbers are considered continuous so if you want them to act as a categorical then switch them to string: ds["color"] = ds["color"].astype(str)
ds.plot.scatter(x="x", y="y", hue="color", ax=plt.figure().gca()) Or if you just want a legend you use add_legend and remove the colorbar: ds.plot.scatter(
x="x",
y="y",
hue="color",
ax=plt.figure().gca(),
add_legend=True,
add_colorbar=False,
) xarray switches between 2 plotting colormaps, sequential or divergent. If you want a different colormap then you can use Lines 164 to 171 in 276b6bf
ds["color"] = ds["color"].astype(str)
xr.set_options(cmap_sequential = "cool")
ds.plot.scatter(x="x", y="y", hue="color", ax=plt.figure().gca()) |
Thanks for the reply! So are you saying that the It was maybe a bit surprising to me that I can try to submit a patch to remove (or deprecate for dataset) the |
Oh, I see you started something along these lines in #7925 |
What happened?
I was trying to do a scatterplot of my data with one dimension determining the color. The dimension has only a few values so I used
hue_style="discrete"
to have a different color for each value. However, the resulting scatterplot has a continuous colorbar, which is the same as when I passhue_style="continuous"
:What did you expect to happen?
The colorbar should have discrete colors. I was also expecting the colors to be from the default matplotlib color palette, C0, C1, etc, when there's less than 10 items, like this:
Although the examples in the documentation show the discrete case also using viridis.
What I was really expecting is a plot like one would get by passing
add_colorbar=False, add_legend=True
:But that may be a bit too automagical.
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
This is the code for the "expected" plot:
Environment
INSTALLED VERSIONS
commit: None
python: 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0]
python-bits: 64
OS: Linux
OS-release: 5.14.0-1059-oem
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: None
libnetcdf: None
xarray: 2023.1.0
pandas: 1.4.3
numpy: 1.23.0
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.5.3
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 44.0.0
pip: 20.0.2
conda: None
pytest: None
mypy: None
IPython: 8.12.2
sphinx: None
I also tried this on main at 3459e6f, the behavior is the same.
The text was updated successfully, but these errors were encountered: