Skip to content
New issue

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

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

Already on GitHub? # to your account

Add Collection.plot() function #15

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

mnlevy1981
Copy link

As a first pass, I allow Collections to contain matplotlib.figure.Figure
objects. Collection.plot() requires a variable argument (for now a string, but
perhaps a list of variables to plot would be better?) and also allows the user
to pass isel_dict to help reduce dimensions. There is a trello card about
introducing sel / isel functionality, and once that's done the isel_dict
argument can be removed.

I like the idea of being able to super-impose line plots (time series of scalar
quantities, or vertical profiles) in a single figure, but I have not made any
progress on that front yet.

I also should add a test for this function.

Fixes #13

mnlevy1981 and others added 2 commits September 16, 2021 11:37
As a first pass, I allow Collections to contain matplotlib.figure.Figure
objects. Collection.plot() requires a variable argument (for now a string, but
perhaps a list of variables to plot would be better?) and also allows the user
to pass isel_dict to help reduce dimensions. There is a trello card about
introducing sel / isel functionality, and once that's done the isel_dict
argument can be removed.

I like the idea of being able to super-impose line plots (time series of scalar
quantities, or vertical profiles) in a single figure, but I have not made any
progress on that front yet.

I also should add a test for this function.
@mnlevy1981
Copy link
Author

I was on the fence about what Collection.plot() should return; maybe instead of an Collection, a regular old dictionary would suffice? Letting a Collection contain figure.Figure objects is likely going to complicate a lot of the other functions provided by the class, and really all I want is a way to access the figures later. For example,

ds = xr.tutorial.open_dataset('rasm')
dsa = xr.tutorial.open_dataset('air_temperature')
collection = xc.Collection({'rasm': ds, 'air_temp': dsa, 'air_temp_to_Tair': dsa.rename({'air': 'Tair'})})
plot_col = collection.plot('Tair', {'time': 0})

plot_col['rasm'].savefig('Tair.png')

After thinking about it more, it didn't make sense to let matplotlib Figures be
valid objects in a Collection, so I stripped that logic out and now
Collection.plot() returns a dict
Better support for Collections that contain DataArrays
If isel_dict contains dim names that are not in the dataset, then we don't try
to plot
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add plot() function
1 participant