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

Export to mpl figure #2790

Merged
merged 4 commits into from
Aug 5, 2020
Merged

Export to mpl figure #2790

merged 4 commits into from
Aug 5, 2020

Conversation

zingale
Copy link
Member

@zingale zingale commented Jul 28, 2020

PR Summary

This reissues #2497

A common operation is to make a matplotlib figure and grid of axes to display slice plots or projection plots, e.g., as shown in this cookbook recipe:

https://yt-project.org/docs/dev/cookbook/complex_plots.html#multipanel-with-axes-labels

This adds a method to PWViewerMPL to automate a lot of that setup. E.g., you would now do that recipe as:


import yt

ds = yt.load_sample("IsolatedGalaxy")

fields = ['density', 'velocity_x', 'velocity_y', 'velocity_magnitude']
p = yt.SlicePlot(ds, 'z', fields)
p.set_log('velocity_x', False)
p.set_log('velocity_y', False)

fig = p.export_to_mpl_figure((2,2))
fig.tight_layout()

fig.savefig("test.png")

PR Checklist

  • pass flake8 yt/
  • pass isort . --check --diff
  • pass black --check yt/
  • New features are documented, with docstrings and narrative docs
  • Adds a test for any bugs fixed. Adds tests for new features.

Copy link
Member

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the stylistic issues caught by travis this still looks good to me ! thanks for reissuing this !

@zingale zingale added the enhancement Making something better label Jul 28, 2020
@zingale
Copy link
Member Author

zingale commented Jul 28, 2020

I think I fixed all the style issues now.

@neutrinoceros
Copy link
Member

neutrinoceros commented Jul 28, 2020

ah, sorry this didn't work ! make sure you have the latest versions for black and isort, older ones may produce different results that won't pass the CI check !

edit: I was looking at the previous jobs apparently, sorry !

Copy link
Member

@munkm munkm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent, and think this is a really nice tool for our users! Thank you so much for the reissue @zingale !!!!

I think it would be nice if you could add an existing example of using this (and maybe also doing some subsequent operations on the matplotlib object) in the narrative docs. The set you linked to seems like a good place. Would you mind adding another section there with this function being used too?

@zingale
Copy link
Member Author

zingale commented Jul 29, 2020

@munkm I could either rewrite the above linked cookbook example to use this, or add an example right afterwards that shows how to do that more easily -- what do you think?

@munkm
Copy link
Member

munkm commented Aug 5, 2020

I think adding an example right afterwards to show how to do it more easily would be great -- that way users can see two methods to get the same result!

@zingale
Copy link
Member Author

zingale commented Aug 5, 2020

done! a new cookbook script appears after the original now.

@zingale
Copy link
Member Author

zingale commented Aug 5, 2020

this is the output from the new cookbook example:
multiplot_export_to_mpl

@munkm
Copy link
Member

munkm commented Aug 5, 2020

You rock! And this feature rocks!!! 🤘 🎸 🚀 Thank you so much @zingale ! I'll merge once the tests pass. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making something better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants