You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on the plot method docstrings (#5285), I (and @keewis) found that the colors kwarg for the Dataset plot methods is not as useful as it could be. In some cases it is silently ignored (warning or error could be raised instead).
For Dataset.plot.scatter, I think it would make sense for a list of colors to be able to be passed to be used for discretehue_style. Currently, the only way you can control these for discrete hue_style is if hue is numeric and you also pass levels.
My original notes on Dataset.plot.scatter:
Yeah, it seems like the colors argument is not used in ds.plot.scatter. But no error is raised, colors is just silently dropped (ax.scatter would raise AttributeError if it weren't) in most cases. I did find that you can get the marker colors to change by passing color or c with a discrete hue_style.
importxarrayasxrimportnumpyasnpds=xr.tutorial.scatter_example_dataset()
ds["c"] = (ds.A.dims, np.random.choice(("r", "g", "b"), ds.A.shape))
ds.plot.scatter("A", "B", hue="c", c=(0, 0, 0)) # works but prints (doesn't raise) warningds.plot.scatter("A", "B", hue="c", color=(0, 0, 0)) # works
However, if you have a continuous hue_style, passing c is ignored (since this is done internally), and passing color raises ValueError since it conflicts with c.
It seems like at the moment, colors is really only intended to be used with contour(f) for levels, like how it is in Matplotlib. Maybe in the future it could be used to allow passing colors to be used in the color cycle for discrete hue_style, but it doesn't currently do that. So for now, maybe in the docstring we should note this current behavior (doing nothing or raising error).
levels is also unused in _dsplot functions, maybe could be removed actually I was able to get colors to sort of work with discrete hue_style by also providing levels, but levels only makes sense for numeric type:
Seaborn has the palette argument that is used for controlling hue. I wonder if they would make sense for Xarray, too. Certainly it's annoying to need to write a loop just to plot a few different colors on the same axis.
Yeah, having a kwarg that is noted to be specifically for the hue variable could make it more clear. It doesn't seem like the Dataset plot methods need to have both cmap and colors. They could be replaced by one, like palette, or keep just colors? But I guess with colors and levels you can make colormaps on the fly, which is convenient. And this does work for plot.scatter, but the hue variable has to be numeric.
Uh oh!
There was an error while loading. Please reload this page.
While working on the plot method docstrings (#5285), I (and @keewis) found that the
colors
kwarg for the Dataset plot methods is not as useful as it could be. In some cases it is silently ignored (warning or error could be raised instead).For
Dataset.plot.scatter
, I think it would make sense for a list of colors to be able to be passed to be used for discretehue_style
. Currently, the only way you can control these for discretehue_style
is ifhue
is numeric and you also passlevels
.My original notes on
Dataset.plot.scatter
:Yeah, it seems like the
colors
argument is not used inds.plot.scatter
. But no error is raised,colors
is just silently dropped (ax.scatter
would raiseAttributeError
if it weren't) in most cases. I did find that you can get the marker colors to change by passingcolor
orc
with a discretehue_style
.However, if you have a continuous
hue_style
, passingc
is ignored (since this is done internally), and passingcolor
raisesValueError
since it conflicts withc
.It seems like at the moment,
colors
is really only intended to be used with contour(f) for levels, like how it is in Matplotlib. Maybe in the future it could be used to allow passing colors to be used in the color cycle for discretehue_style
, but it doesn't currently do that. So for now, maybe in the docstring we should note this current behavior (doing nothing or raising error).actually I was able to getlevels
is also unused in_dsplot
functions, maybe could be removedcolors
to sort of work with discretehue_style
by also providinglevels
, butlevels
only makes sense for numeric type:Originally posted by @zmoon in #5285 (comment)
The text was updated successfully, but these errors were encountered: