[yt-dev] Display name formatting

Matthew Turk matthewturk at gmail.com
Sat Sep 8 12:27:09 PDT 2012


Hi Nathan,

On Fri, Sep 7, 2012 at 7:06 PM, Nathan Goldbaum <nathan12343 at gmail.com> wrote:
> Hi all,
>
> I've just run into an issue with the way plot window currently handles the
> derived field display_names.  Everything works great so long as the display
> name is an ascii string (true for 99% of yt fields) but if I define a new
> field and I want the display name to include some latex macros, things
> currently break.
>
> I've hacked up a solution in this changeset:
> https://bitbucket.org/ngoldbaum/yt-cleancopy/changeset/5087f6769726a9527b508470eb1b904bfe6beacd
>
> This allows me to make plots like this: http://i.imgur.com/a8G9e.png Or
> this: http://i.imgur.com/TTgAY.png if I define the fields as in this paste:
> http://paste.yt-project.org/show/2683/
>
> This wasn't a problem using PlotCollection since the colorbar label wasn't
> rendered in mathtext unless the display_name string was explicitly passed as
> mathtext.  When I finished up plot window I decided to force the axis labels
> and colorbar labels to be mathtext so that the unit label and field name are
> rendered in the same font.
>
> A simpler solution would be to go back to annotating the labels using the
> matplotlib fonts.  I'm -1 on that since I think the plots don't look as
> nice.

I'd also prefer that we attempt to make Mathtext rendering the
default.  If you look at the old plot collection, I thought we in fact
*did* do this for the field names, which led to hilarious things like
H2I_Fraction having an F for a subscript hanging off the i.  The code,
which was a bit ridiculous, was this:

        data_label = r"$\rm{%s}" % field_name.replace("_"," ")
        if field_name in self.pf.field_info:
            data_label += r"\/\/ (%s)" %
(self.pf.field_info[field_name].get_units())
        data_label += r"$"

But as you note, for some reason display_name was never used.

Anyway, I'm fine with making it work, but please do make sure that it
also works for the units, which as of right now do not have a
preceding $.  In your example images there aren't any units listed.

-Matt

>
> Personally, I'm +1 on my changeset but since this is a biggish change that
> might interfere with user-defined fields, I wanted to open a discussion on
> the dev list about how to handle the issue before submitting a PR.
>
> Cheers,
>
> Nathan
>
> _______________________________________________
> yt-dev mailing list
> yt-dev at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org
>



More information about the yt-dev mailing list