issue_comments: 981065902
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/pull/5622#issuecomment-981065902 | https://api.github.com/repos/pydata/xarray/issues/5622 | 981065902 | IC_kwDOAMm_X846eeCu | 14371165 | 2021-11-28T11:11:00Z | 2021-11-28T11:11:00Z | MEMBER | I'm struggling getting categorical colorbars to work nicely:
```python
import numpy as np
import xarray as xr
das = [
xr.DataArray(
np.random.randn(3, 3, 4, 4, 2),
dims=["x", "row", "col", "hue", "size"],
coords=[range(k) for k in [3, 3, 4, 4, 2]],
)
for _ in [1, 2]
]
ds = xr.Dataset({"A": das[0], "B": das[1]})
ds.hue.name = "huename"
ds.hue.attrs["units"] = "hunits"
ds.x.attrs["units"] = "xunits"
ds.col.attrs["units"] = "colunits"
ds.row.attrs["units"] = "rowunits"
ds.A.attrs["units"] = "Aunits"
ds.B.attrs["units"] = "Bunits"
ds2 = ds.copy()
ds2["hue"] = ["d", "a", "c", "b"]
g = ds2.plot.scatter(
x="A",
y="B",
hue="hue",
markersize="size",
col="col",
add_legend=True,
add_colorbar=True,
)
```
My goals are: * 4 colors for 4 categories * ticks should be centered on the color. One of the issues are that https://github.com/pydata/xarray/blob/135a3351bf77a4a55e76a8c60b40852ec10cdd4a/xarray/plot/utils.py#L69 Seems to be focused on contour(f) plots only which leads to the colorbar having N-1 colors all the time. Any ideas how to solve this is appreciated. Related links: * https://stackoverflow.com/questions/14777066/matplotlib-discrete-colorbar * https://gist.github.com/jakevdp/8a992f606899ac24b711 |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
948049609 |