Skip to content

rendering multiple variables from an xarray dataset? #39

Discussion options

You must be logged in to vote

A bit convoluted, but it gets the job done! The benefit of this is you can also customize how you want the plot.

import xarray as xr
import hvplot.xarray
import matplotlib.pyplot as plt
from streamjoy import stream, wrap_matplotlib

@wrap_matplotlib()
def renderer(da):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    da.plot.line(x="lon", ax=ax, ylim=(250, 600))
    return fig


ds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(0, 100))
ds["airx2"] = ds.air * 2
ds = ds.mean(["lat"])

stream(ds.to_array(), dim="time", renderer=renderer).write()

Underneath, the renderer essentially just does

ds.plot()

So what I did was first explore how to get that plot through basic…

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Thomas-Moore-Creative
Comment options

Answer selected by Thomas-Moore-Creative
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@ahuang11
Comment options

@Thomas-Moore-Creative
Comment options

@Thomas-Moore-Creative
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants