[yt-users] Fonts size in the Projection plot.

Ji Suoqing jisuoqing at gmail.com
Mon Mar 25 21:07:36 PDT 2013


Hi Junhwan,

I can provide you a quick hack to do this, while it is ugly and be careful to save your backup file.

In the file:

src/yt-hg/yt/visualization/plot_window.py

You could search for the following lines:

class PlotWindow(object):
    _plot_valid = False
    _colorbar_valid = False
    _contour_info = None
    _vector_info = None
    _frb = None
    def __init__(self, data_source, bounds, buff_size=(800,800), antialias=True,
                 periodic=True, origin='center-window', oblique=False, fontsize=15):

In the last line, change the font size to a larger number.

After that you'll find both the ticks and labels of axis and colorbar become larger. However, if you use log plot, you'll find the exponent number at the top of the axis remains small. Then you could add these in your own script:

import matplotlib

matplotlib.rcParams.update({'font.size': YOURSIZE})

My yt version might be a little out-of-date, so please also be cautious when you do the modification. Hope it works for you, although it's not an elegant way...

Best wishes,
Suoqing


On Mar 25, 2013, at 11:38 PM, Jun-Hwan Choi <jhchoi at pa.uky.edu> wrote:

> Dear Nathan,
> 
> Thank you for you help.
> However, when I try to follow your suggestion, yt complains that 
> >> slc.set_font(font_dict)
> >> AttributeError: 'ProjectionPlot' object has no attribute 'set_font'
> Meanwhile, I try your approach only for annotate_text then it works.
> So, now I can control the text size but I still can not find how increase x y label and tick size.
> Is there other way to do so?
> 
> Thank you,
> Junhwan
> 
> 
> On Mon, Mar 25, 2013 at 10:46 PM, Nathan Goldbaum <nathan12343 at gmail.com> wrote:
> Hi Junhwan,
> 
> You can set the font properties using the set_font function:
> 
> >>> slc = SlicePlot(pf, 'x', 'Density')
> >>> font_dict = {'family':'sans-serif', 'style':'italic',
>                         'weight':'bold', 'size':24}
> >>> slc.set_font(font_dict)
> 
> Here, font_dict is a dictionary of keywords that will be passed to the matplotlib FontProperties object for the plot.  For more details about FontProperties, take a look at the matplotlib documentation: http://matplotlib.org/api/font_manager_api.html#matplotlib.font_manager.FontProperties
> 
> One caveat is that the axes labels use MathText which is tied to a special computer modern font that is bundled with matplotlib.  For that reason, you will only be able to adjust the size of the axes labels, not the font.
> 
> Another caveat is that you cannot set the tick label color using set_font.  Instead, you'll need to iterate over the actual tick label objects as in this example from the docs: http://yt-project.org/doc/cookbook/simple_plots.html?highlight=dinosaurs#accessing-and-modifying-plots-directly
> 
> Finally, you'll need to set the font properties for the text annotation separately:
> 
> >>> slc.annotate_text((-45,42.5), "a)", data_coords=False, text_args = font_dict)
> 
> The text_args keyword of annoate_text does accept color as a keyword, so you'll be able to pass it in with font_dict.
> 
> The full list of allowed keywords for text_args is on this page from the matplotlib docs: http://matplotlib.org/users/text_props.html
> 
> Hope that's helpful.  Sorry that's not as simple as it could be, this is one area of the plotting routines where it would be nice to simplify things.
> 
> -Nathan
> 
> On Mon, Mar 25, 2013 at 6:13 PM, Jun-Hwan Choi <jhchoi at pa.uky.edu> wrote:
> Hi yt user,
> 
> I make a very simple projection plot using following script:
> 
> ==========
> from yt.mods import *
> 
> # Load the dataset.
> pf = load("../RunDM1/DD0134/DD0134")
> center = na.array([0.5,0.5,0.5,])
> 
> # Making slice
> slc = ProjectionPlot(pf, 2,'Density', center,(100, 'pc') , 'Density')
> slc.annotate_text((-45,42.5), "a)", data_coords=False)
> slc.save("Run1")
> ==========
> 
> It generate plot with x, y, z labels and ticks as well text "a)"
> I would like to increase the font size of label, ticks, and text.
> I also change the color of the text.
> I think it is very basic operation, but I can not find the way.
> Can anyone help me?
> 
> Thanks in advance,
> Junhwan
> 
> 
> -- 
> --------------------------------------------------------------
> Jun-Hwan Choi, Ph.D.
> Department of Physics and Astronomy, University of Kentucky
> Tel: (859) 897-6737        Fax: (859) 323-2846
> Email: jhchoi at pa.uky.edu   URL: http://www.pa.uky.edu/~jhchoi
> --------------------------------------------------------------
> 
> 
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> 
> 
> 
> 
> 
> -- 
> --------------------------------------------------------------
> Jun-Hwan Choi, Ph.D.
> Department of Physics and Astronomy, University of Kentucky
> Tel: (859) 897-6737        Fax: (859) 323-2846
> Email: jhchoi at pa.uky.edu   URL: http://www.pa.uky.edu/~jhchoi
> --------------------------------------------------------------
> 
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20130326/9d2a4ddb/attachment.html>


More information about the yt-users mailing list