Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plot() function #13

Open
mnlevy1981 opened this issue Sep 16, 2021 · 2 comments · May be fixed by #15
Open

Add plot() function #13

mnlevy1981 opened this issue Sep 16, 2021 · 2 comments · May be fixed by #15
Assignees

Comments

@mnlevy1981
Copy link

@andersy005 or @mgrover1 -- I'm not totally sure where to start with this one, and maybe I'm overthinking it... but I'm getting caught up in how overloaded xr.DataArray.plot() is, so I don't really know what the desired output of this function is. Suppose we have

import xarray as xr
import xcollection as xc
ds = xr.tutorial.open_dataset('rasm')
dsa = xr.tutorial.open_dataset('air_temperature')
collection = xc.Collection({'rasm': ds, 'air_temp': dsa})

How would you call collection.plot() and what would you expect the plot to look like? I was initially picturing something like

def plot(var, *args, **kwargs):

but collection['rasm']['Tair'].plot(); is a histogram and you need collection['rasm']['Tair'].isel(time=___).plot(); to get a contour plot. So maybe

def plot(var, isel_dict={}, *args, **kwargs):

and we could call

collection.plot('Tair', {'time': ___})

but then what happens if multiple datasets in the collection contain var? Should we allow collections to containmatplotlib.figure.Figure objects? Then collection.plot() could return a collection of figures?

That seems like useful behavior for contour plots, but what about line plots? If I want to look at a time series or vertical profile at a given location (or maybe of a global mean), then should there be an option to return a single figure containing lines from all acceptable datasets? E.g. if I have a collection of 10 datasets, and five of them contain the variable Tair, then maybe I want to plot all five together with a legend containing the key for each dataset?

@mnlevy1981 mnlevy1981 self-assigned this Sep 16, 2021
@jukent
Copy link
Contributor

jukent commented Sep 16, 2021

I think I want to look more into how xarray.DataSet.plot() works. How does that plot method determine if we have a line or contour plot? And since when you have multiple time steps, for a contour plot it only plots the first one -- is it more similar to only plot the first DataSet in our Collection (with a kwarg for changing which DataSet it is? I am interested to hear @andersy005 and @mgrover1's thoughts.

@mnlevy1981 mnlevy1981 linked a pull request Sep 16, 2021 that will close this issue
@mnlevy1981
Copy link
Author

Another design question: do we want to accept Collection.plot([var1, var2])? If so, does that mean returning a dictionary of dictionaries? Right now, Collection.plot(var) returns a dictionary of plots: return_dict[key] = <matplotlib.figure.Figure> but maybe it should be return_dict[key][var] = <matplotlib.figure.Figure> to support multiple variables at a time? I like the similarity between the existing .plot() results and the Collection structure but don't see how to keep that and allow plotting multiple variables at a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Paused
Development

Successfully merging a pull request may close this issue.

2 participants