Making tick labels use a serif font by default, bumping the default font size to 18.

#444 Merged at fb86a36
Repository
ngoldbaum
Branch
yt
Repository
yt_analysis
Branch
yt
Author
  1. Nathan Goldbaum
Reviewers
Description

This reworks the way we set fonts for plot window plots, leveraging the FontProperty object defined in recent versions of matplotlib.

I've added a new method that allows finer control over the fonts. I tried to allow additional control over the axis labels and colorbar labels, but that's not possible for MathText, which always use a computer modern font as far as I can tell. It's still possible to adjust the font size for the MathText labels, just not the actual font its self. I've changed the default font to a STIX font that looks a lot like the computer modern font used by the MathText parser. Unfortunately we can't use the exact same font for obscure reasons.

These changes make a totally subjective, but, in my opinion, significant improvement to the readability of the axes and tick labels, bringing them closer to publication quality.

Edit: anticipating Matt's objections ;)

Edit 2: Updating per stephen's suggestion.

Edit 3: Removing the fontsize attribute from the base plot window class. Using _font_properties exclusively instead.

Edit 4: Updating to address comments.

Comments (6)

  1. MattT

    Hi Nathan,

    So it's not entirely clear to me from reading this code where the fontsize is specified, where it gets set, and how that gets threaded through. In general I worry that if we continue to add additional constructor arguments, we'll be back in the place we were with the PlotCollection, at an unmanageable set of wrappers around matplotlib. It looks like in some areas you're using font_properties, which would be a nice change, and in others not.

    Could you briefly outline in a comment what the actual changes here do, and how they shift interaction?

    In the future I would like to start thinking about pushing back toward much simpler object creation, with fewer keyword arguments, and enabling more getters and setters. One problem with trying to retain backwards API compatibility is that if you add an argument, you can't really take it away.

    Thank you for doing this, by the way. The images are markedly improved!

    1. Nathan Goldbaum author

      Hi Matt,

      This doesn't actually define any new keyword arguments, so no worries on that front. I did touch the initializers in several places, but that was only to add spaces between the arguments for code readability.

      Before this PR, the only way to control the fonts was via the fontsize keyword. Now, I allow further customization beyond just the size via set_font. At initialization, set_font gets called on line 811 to set the font size following the user-supplied fontsize keyword and set the font to the STIX font I locate on line 809. These fonts are bundled with matplotlib, so no need to worry about not being able to find them.

      Previously it wasn't possible to set the font size after the plot is created, so this makes it possible to do so, along with several other font customizations.

      I think this goes along with your desire to reduce the number of keyword arguments. I guess I'm confused about why you think this adds additional complexity to the initializers.

    2. Nathan Goldbaum author

      Would you prefer I not carry around the fontsize attribute any longer? I think I could figure out a way to do that.

      1. Nathan Goldbaum author

        I've gone ahead and done this. Let me know what you think of the updated PR.

  2. MattT

    This looks good to me, and I think the balance between having fontsize in the initializer, and the set_fonts function, is good. I've only made a few comments below, and then it should be set.