home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 775390720

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/4820#issuecomment-775390720 https://api.github.com/repos/pydata/xarray/issues/4820 775390720 MDEyOklzc3VlQ29tbWVudDc3NTM5MDcyMA== 14371165 2021-02-08T19:34:46Z 2021-02-08T19:35:57Z MEMBER

I think making the dataset plots a thin wrapper for the dataarray plot functions is the way to go. I think most things for the lineplot works as intended now. I'm not sure about the decorator though. It's a bit too simple compared to _dsplot at the moment.

Supporting linewidth in plots should be possible but this is for a future pr I think. I did a small proof of concept here: ```python def _lineplot(ds, x, y, hue, linewidth): if len(ds[y].dims) > 3: raise NotImplementedError("too many dims.")

fig, ax = plt.subplots(1, 1)
for i, width in enumerate(ds[linewidth]):
    # Filter along linewidth:
    dsi = ds.isel(**{linewidth: i})

    # Values to plot:
    xplt = dsi[x]

    # if xplt has no dims:
    (xdim,) = xplt.dims
    (huedim,) = dsi[hue].dims
    yplt = dsi[y].transpose(..., xdim, huedim)

    # Set plot properties:
    len_lines = len(ds[hue])
    cmap = plt.get_cmap("viridis", len_lines)
    colors = plt.cycler(color=cmap(np.arange(len_lines)))
    lw = plt.cycler(lw=[1 + i * 3])
    ax.set_prop_cycle(colors * lw)

    # p = xr.broadcast(xplt, yplt)
    plt.plot(xplt, yplt, label=width.values)
    plt.legend()

# ax.plot doesn't return a mappable that fig.colorbar can parse. Create
# one and return that one instead:
norm = plt.Normalize(vmin=ds[hue].min(), vmax=ds[hue].max())
primitive = plt.cm.ScalarMappable(cmap=plt.get_cmap("viridis"), norm=norm)
fig.colorbar(mappable=primitive)

return fig, ax

ds = xr.tutorial.scatter_example_dataset() ds1 = ds.sel(z=0) _lineplot(ds=ds1, x="y", y="A", hue="w", linewidth="x") ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  787732195
Powered by Datasette · Queries took 0.439ms · About: xarray-datasette