Fixing some longstanding issues with plot layouts.

#723 Merged
Repository
ngoldbaum
Branch
yt-3.0
Repository
yt_analysis
Branch
yt-3.0
Author
  1. Nathan Goldbaum
Reviewers
Description

This PR completely refactors the code that generates plot layouts. The quick upside is that this completely fixes the longstanding issue with plots that have non-unit aspect ratios. See e.g. Issue #735.

To make that a bit more concrete, take a look at the following test plotting script:

from yt.mods import *
ds = load('IsolatedGalaxy/galaxy0030/galaxy0030')
sl = SlicePlot(ds, 2, 'density')
sl.set_width(((25, 'kpc'), (5, 'kpc')))
sl.save(mpl_kwargs={'facecolor':'red'})

This creates a plot and saves it with a red background color, making it easier to see the full extent of the figure on a white background.

Before applying this PR, I get the following:

galaxy0030_Slice_z_density.png

After applying this PR I get:

galaxy0030_Slice_z_density.png

I debugged this using an IPython notebook widget. If you have the IPython 2.0 beta installed you can download the notebook from nbviewer and test it out yourself.

This introduces some design changes in the plotting code:

  • Moves the layout code to ImagePlotMPL. The layout constants are still calculated in subclasses, making it possible to have custom layouts for PlotWindow and PhasePlot.
  • Fixes a bug where colorbar and axis toggling do not persisting if a plot is modified after the element is toggled.
  • set_font now preserves the family and size settings, which we have custom defaults for.
  • Added set_font_size. I find it useful to have this but I'll remove it if anyone thinks it clutters the API.

Update: responding to comments.

Comments (3)

  1. MattT

    Thanks for taking the time to go through all of this, @ngoldbaum . I'm really happy to see these cool improvements.

  2. Sam Skillman

    Hi @ngoldbaum this looks great. I tested your stuff in the notebook, and they are definitely improvements. It is also worth noting that the (matplotlib) dpi is another handle on how figure size can vary. I agree with the setup now to leave it a 10 inches and figure out a way to handle notebook optimizations later.