[yt-users] how to make a SlicePlot colorbar use mathtext?
Michael Zingale
michael.zingale at stonybrook.edu
Wed Aug 20 10:22:44 PDT 2014
Hi Nathan, the issue is getting it to be 10^6 instead of 1.e6 for the
offset text in the colorbar. This just works usually in matplotlib, so yt
is doing something to turn it off, but I don't know what. I think I'll
just get the fixed-resolution buffers from the slice object and then just
use matplotlib to plot it, since I can make it look right there. I poked
around yt quite a bit, but I don't see what's wrong.
On Wed, Aug 20, 2014 at 1:16 PM, Nathan Goldbaum <nathan12343 at gmail.com>
wrote:
> Hi Mike,
>
> It will use MathText if you ask for a logarithmically scaled colorbar.
>
> There's probably a way to do it by spelunking a bit inside the matplotlib
> API, but I don't know of an easy way to do it off-hand.
>
> If all you care about is the font, you can also use the 'stixgeneral' font
> family, which is actually the font that matplotlib uses internally to
> display mathtext. You can change the font globally by updating your
> matplotlibrc or changing your matplotlib configuration at the top of your
> script.
>
> Sorry I can't be more helpful. Let us know if you come up with a solution
> here.
>
> -Nathan
>
>
> On Wed, Aug 20, 2014 at 8:38 AM, Michael Zingale <
> michael.zingale at stonybrook.edu> wrote:
>
>> here's my script (also here:
>> http://bender.astro.sunysb.edu/random/slice3plot.py )
>>
>> #!/bin/env python
>>
>> import argparse
>>
>> import yt
>>
>> import matplotlib
>> import matplotlib.pyplot as plt
>> from mpl_toolkits.axes_grid1 import AxesGrid
>>
>> def doit(file, var, log):
>>
>> # load the data
>> ds = yt.load(file)
>> dd = ds.all_data()
>>
>> center = 0.5*(ds.domain_left_edge + ds.domain_right_edge)
>>
>> # see
>> http://yt-project.org/docs/3.0/cookbook/complex_plots.html#multipanel-with-axes-labels
>>
>> fig = plt.figure()
>>
>> grid = AxesGrid(fig, (0.1, 0.1, 0.85, 0.85),
>> nrows_ncols = (1, 3),
>> axes_pad = 1.1,
>> label_mode = "all",
>> share_all = False,
>> cbar_location = "right",
>> cbar_mode = "each",
>> cbar_size = "3%",
>> cbar_pad = "0%")
>>
>> formatter = matplotlib.ticker.ScalarFormatter(useMathText=True)
>> formatter.set_powerlimits((-3,3))
>>
>> for i, d in enumerate(["x", "y", "z"]):
>>
>> p = yt.SlicePlot(ds, d, var, center=(center[0], center[1],
>> center[2]),
>> origin="native", fontsize=10)
>> p.set_log(var, log)
>>
>> plot = p.plots[var]
>> plot.figure = fig
>> plot.axes = grid[i].axes
>> plot.cax = grid.cbar_axes[i]
>>
>> #cb.formatter.set_scientific(True)
>> #cb.formatter.set_powerlimits((-3,3))
>> #plot.cax.yaxis.set_major_formatter(formatter)
>>
>> cb = plot.cb
>> cb.formatter = formatter
>> cb.update_ticks()
>>
>>
>> p._setup_plots()
>>
>> ax = plot.axes
>> ax.xaxis.set_major_formatter(formatter)
>> ax.yaxis.set_major_formatter(formatter)
>>
>> ax.xaxis.offsetText.set_fontsize("small")
>> ax.yaxis.offsetText.set_fontsize("small")
>>
>>
>> fig.set_size_inches(12.80, 7.20)
>>
>> plt.savefig("test.png")
>>
>>
>>
>>
>> if __name__ == "__main__":
>>
>> parser = argparse.ArgumentParser()
>>
>> parser.add_argument("--log", help="plot the log of the variable",
>> action="store_true")
>>
>> parser.add_argument("file", help="the name of the file to read",
>> type=str)
>> parser.add_argument("var", help="the name of the variable to plot",
>> type=str)
>>
>> args = parser.parse_args()
>>
>> doit(args.file, args.var, args.log)
>>
>>
>>
>> On Wed, Aug 20, 2014 at 11:34 AM, Michael Zingale <
>> michael.zingale at stonybrook.edu> wrote:
>>
>>> yeah, I was doing that -- it doesn't have an effect.
>>>
>>>
>>> On Wed, Aug 20, 2014 at 11:33 AM, Chris Malone <chris.m.malone at gmail.com
>>> > wrote:
>>>
>>>> Hey Mike,
>>>>
>>>> I'm not sure if this is the issue or not, but after you apply your
>>>> formatter to the colorbar, you need to call cbar.update_ticks() for them to
>>>> actually change.
>>>>
>>>> Chris
>>>>
>>>>
>>>> On Wed, Aug 20, 2014 at 9:12 AM, Michael Zingale <
>>>> michael.zingale at stonybrook.edu> wrote:
>>>>
>>>>> Does anyone know how to make a SlicePlot colorbar from yt use mathtext
>>>>> in the tick labels? I am doing the following in a loop over x, y, z planes:
>>>>>
>>>>>
>>>>> p = yt.SlicePlot(ds, d, var, center=(center[0], center[1],
>>>>> center[2]),
>>>>> origin="native", fontsize=10)
>>>>> p.set_log(var, log)
>>>>>
>>>>> plot = p.plots[var]
>>>>> plot.figure = fig
>>>>> plot.axes = grid[i].axes
>>>>> plot.cax = grid.cbar_axes[i]
>>>>>
>>>>> I can get at the colorbar object via cb = plot.cb, but I can't seem to
>>>>> turn on mathtext. I can modify the axes to use my formatter so they look
>>>>> pretty, but I've tried to set a colorbar formatter with no success.
>>>>>
>>>>> Here's my image:
>>>>>
>>>>> http://bender.astro.sunysb.edu/random/test.png
>>>>>
>>>>> Notice that the offset text for the colorbar is "1.e6" instead of in
>>>>> latex (I still have to remove the offset text for the two rightmost y-axes
>>>>> later, but I know how to do that).
>>>>>
>>>>> Mike
>>>>>
>>>>> --
>>>>> Michael Zingale
>>>>> Associate Professor
>>>>>
>>>>> Dept. of Physics & Astronomy • Stony Brook University • Stony Brook,
>>>>> NY 11794-3800
>>>>> *phone*: 631-632-8225
>>>>> *e-mail*: Michael.Zingale at stonybrook.edu
>>>>> *web*: http://www.astro.sunysb.edu/mzingale
>>>>>
>>>>> _______________________________________________
>>>>> yt-users mailing list
>>>>> yt-users at lists.spacepope.org
>>>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> yt-users mailing list
>>>> yt-users at lists.spacepope.org
>>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>>>
>>>>
>>>
>>>
>>> --
>>> Michael Zingale
>>> Associate Professor
>>>
>>> Dept. of Physics & Astronomy • Stony Brook University • Stony Brook, NY
>>> 11794-3800
>>> *phone*: 631-632-8225
>>> *e-mail*: Michael.Zingale at stonybrook.edu
>>> *web*: http://www.astro.sunysb.edu/mzingale
>>>
>>
>>
>>
>> --
>> Michael Zingale
>> Associate Professor
>>
>> Dept. of Physics & Astronomy • Stony Brook University • Stony Brook, NY
>> 11794-3800
>> *phone*: 631-632-8225
>> *e-mail*: Michael.Zingale at stonybrook.edu
>> *web*: http://www.astro.sunysb.edu/mzingale
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>>
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
--
Michael Zingale
Associate Professor
Dept. of Physics & Astronomy • Stony Brook University • Stony Brook, NY
11794-3800
*phone*: 631-632-8225
*e-mail*: Michael.Zingale at stonybrook.edu
*web*: http://www.astro.sunysb.edu/mzingale
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20140820/f5722164/attachment.html>
-------------- next part --------------
_______________________________________________
yt-users mailing list
yt-users at lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
More information about the yt-users
mailing list