issues: 894819396
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
894819396 | MDU6SXNzdWU4OTQ4MTkzOTY= | 5337 | `colors` in Dataset plot methods | 15079414 | open | 0 | 2 | 2021-05-18T22:01:48Z | 2021-07-04T01:12:45Z | CONTRIBUTOR | While working on the plot method docstrings (#5285), I (and @keewis) found that the For My original notes on
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`.
```python
import xarray as xr
import numpy as np
ds = 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) warning
ds.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:
```python
ds["c2"] = (ds.A.dims, np.random.choice((1, 2, 3), ds.A.shape))
ds.plot.scatter("A", "B", hue="c2", colors=["r", "g", "b"], levels=[1, 2, 3, 4]) # works (rgb)
ds.plot.scatter("A", "B", hue="c2", hue_style="discrete", colors=["r", "g", "b"]) # `colors` does nothing
```
_Originally posted by @zmoon in https://github.com/pydata/xarray/pull/5285#discussion_r632986368_
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/5337/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |