<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">Many thanks Nathan<br><br></div><div class="gmail_default" style="font-family:monospace,monospace">for the brilliant reply and solution. I could edit it easily with plot._font_properties.</div><div class="gmail_extra"><div style="font-family:monospace,monospace" class="gmail_default">​Only, when the colorbar is horizontal one should use new_ax.xaxis instead of new_ax.yaxis<br></div><div style="font-family:monospace,monospace" class="gmail_default">(took me a bit to spot it), but it is true that like this one can have complete control over <br>the colorbar.<br></div><div style="font-family:monospace,monospace" class="gmail_default">​<br></div><div style="font-family:monospace,monospace" class="gmail_default">Best,<br></div><br><div class="gmail_quote">On Sat, Jul 8, 2017 at 8:34 PM,  <span dir="ltr"><<a href="mailto:yt-users-request@lists.spacepope.org" target="_blank">yt-users-request@lists.spacepope.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send yt-users mailing list submissions to<br>
        <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:yt-users-request@lists.spacepope.org">yt-users-request@lists.<wbr>spacepope.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:yt-users-owner@lists.spacepope.org">yt-users-owner@lists.<wbr>spacepope.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of yt-users digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. customizing colorbar (sacielo)<br>
   2. Re: customizing colorbar (Nathan Goldbaum)<br>
<br>
<br>
------------------------------<wbr>------------------------------<wbr>----------<br>
<br>
Message: 1<br>
Date: Sat, 8 Jul 2017 10:48:20 +0200<br>
From: sacielo <<a href="mailto:sacielo@gmail.com">sacielo@gmail.com</a>><br>
To: <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
Subject: [yt-users] customizing colorbar<br>
Message-ID:<br>
        <<a href="mailto:CALAgqdL%2BfOwJoB%2B8---Yh3YYHbLwimDS%2BDrbO0GpbV3iXCeSPQ@mail.gmail.com">CALAgqdL+fOwJoB+8---<wbr>Yh3YYHbLwimDS+<wbr>DrbO0GpbV3iXCeSPQ@mail.gmail.<wbr>com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Hello,<br>
<br>
I was trying to change the looks of the colorbar of slice plots; first I<br>
found out I could create a new colorbar in a new position. I obtained<br>
something I like very much like this (for some dataset ds):<br>
<br>
?myvar = 'density'<br>
sl = yt.SlicePlot(ds, 'x', myvar, center='c', width=(3,'kpc'))<br>
sl.hide_colorbar()<br>
sl.hide_axes()<br>
plot   = sl.plots[myvar]<br>
fig    = plot.figure<br>
new_ax = fig.add_axes((0.025,0.94,0.75,<wbr>0.025))<br>
??<br>
cb     = plot.figure.colorbar(plot.<wbr>image, new_ax, extend='both',<br>
orientation='horizontal', format='%.0E'?)?<br>
sl._setup_plots()<br>
<br>
?The only problem now is I cannot change the font properties of this new<br>
colorbar. Even trying?, e.g.:<br>
<br>
sl.set_font({'family': 'sans-serif', 'style': 'normal', 'weight': 'normal',<br>
'size': 36})<br>
<br>
?will change all fonts, including the default colorbar, all text and<br>
annotations, but not this new colorbar.<br>
I think plot.figure.colorbar does not accept any argument to edit the font.<br>
<br>
Do you know how I could change this? Or maybe have I gone down the wrong<br>
path?<br>
?I wouldn't like to do all manually with matplotlib, as I plan to add many<br>
more yt annotations to this plot, which all work very well.<br>
<br>
?Thank you!?<br>
<br>
?Best,?<br>
<br>
--<br>
Salvatore<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20170708/ad1d41c4/attachment.html" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>pipermail/yt-users-spacepope.<wbr>org/attachments/20170708/<wbr>ad1d41c4/attachment.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Sat, 8 Jul 2017 08:29:28 -0500<br>
From: Nathan Goldbaum <<a href="mailto:nathan12343@gmail.com">nathan12343@gmail.com</a>><br>
To: Discussion of the yt analysis package<br>
        <<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a>><br>
Subject: Re: [yt-users] customizing colorbar<br>
Message-ID:<br>
        <CAJXewOns=<a href="mailto:aZfkkYoxaP%2B2HuBLahkrsU4zyMzp__yoiKSW-FcoA@mail.gmail.com">aZfkkYoxaP+<wbr>2HuBLahkrsU4zyMzp__yoiKSW-<wbr>FcoA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
On Sat, Jul 8, 2017 at 3:48 AM, sacielo <<a href="mailto:sacielo@gmail.com">sacielo@gmail.com</a>> wrote:<br>
<br>
> Hello,<br>
><br>
> I was trying to change the looks of the colorbar of slice plots; first I<br>
> found out I could create a new colorbar in a new position. I obtained<br>
> something I like very much like this (for some dataset ds):<br>
><br>
> ?myvar = 'density'<br>
> sl = yt.SlicePlot(ds, 'x', myvar, center='c', width=(3,'kpc'))<br>
> sl.hide_colorbar()<br>
> sl.hide_axes()<br>
> plot   = sl.plots[myvar]<br>
> fig    = plot.figure<br>
><br>
<br>
Rather than creating a new colorbar, you can get access to the original<br>
colorbar via plot.cb and the original colorbar axes via plot.cax.<br>
<br>
However, I don't think there's an easy way to make a colorbar horizontal<br>
after its already been created.<br>
<br>
Right now yt's plots don't have a mode to create a horizontal colorbar.<br>
They aren't really designed for total customization, they're optimized for<br>
quick plotting and as such make many assumptions about how the plots look.<br>
So you're running into a mismatch between assumptions the plotting system<br>
needs to make about how the plots should look to avoid making people<br>
manually create plots every time, and the inflexibility that implies if you<br>
really *do* want to manually plot something.<br>
<br>
If you want fully manual control over the plot looks and don't want to use<br>
the axes and colorbar yt is creating, then you may want to manually<br>
construct the plots using an image buffer. Here are some examples in the<br>
docs on how to do that:<br>
<br>
<a href="http://yt-project.org/docs/dev/visualizing/manual_plotting.html" rel="noreferrer" target="_blank">http://yt-project.org/docs/<wbr>dev/visualizing/manual_<wbr>plotting.html</a><br>
<a href="http://yt-project.org/docs/dev/cookbook/complex_plots.html?highlight=manual#multi-plot-slice-and-projections" rel="noreferrer" target="_blank">http://yt-project.org/docs/<wbr>dev/cookbook/complex_plots.<wbr>html?highlight=manual#multi-<wbr>plot-slice-and-projections</a><br>
<br>
Of course that doesn't let you use the yt plot annotations, so I don't<br>
think that's what you're looking for either.<br>
<br>
<br>
> new_ax = fig.add_axes((0.025,0.94,0.75,<wbr>0.025))<br>
> ??<br>
> cb     = plot.figure.colorbar(plot.<wbr>image, new_ax, extend='both',<br>
> orientation='horizontal', format='%.0E'?)?<br>
> sl._setup_plots()<br>
><br>
> ?The only problem now is I cannot change the font properties of this new<br>
> colorbar. Even trying?, e.g.:<br>
><br>
> sl.set_font({'family': 'sans-serif', 'style': 'normal', 'weight':<br>
> 'normal', 'size': 36})<br>
><br>
<br>
Another way to do this using your current approach would be to customize<br>
the colorbar you're creating using the plot's new FontProperties instance.<br>
After calling this function you can get access to the FontProperties<br>
instance used via plot._font_properties.<br>
<br>
Next, you'd need to apply the new FontProperties to the tick marks and<br>
labels on the colorbar you've created:<br>
<br>
    fp = plot._font_properties<br>
    labels = new_ax.yaxis.get_ticklabels()<br>
    labels += [new_ax.yaxis.label, new_ax.yaxis.get_offset_text()<wbr>]<br>
    for label in labels:<br>
        label.set_fontproperties(fp)<br>
<br>
Here's a worked out example:<br>
<br>
<a href="https://gist.github.com/anonymous/9a80cd6f0148d1df362a2c9cfb6d10da" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>anonymous/<wbr>9a80cd6f0148d1df362a2c9cfb6d10<wbr>da</a><br>
<br>
<br>
><br>
> ?will change all fonts, including the default colorbar, all text and<br>
> annotations, but not this new colorbar.<br>
> I think plot.figure.colorbar does not accept any argument to edit the font.<br>
><br>
> Do you know how I could change this? Or maybe have I gone down the wrong<br>
> path?<br>
> ?I wouldn't like to do all manually with matplotlib, as I plan to add many<br>
> more yt annotations to this plot, which all work very well.<br>
><br>
> ?Thank you!?<br>
><br>
> ?Best,?<br>
><br>
> --<br>
> Salvatore<br>
><br>
> ______________________________<wbr>_________________<br>
> yt-users mailing list<br>
> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20170708/39ec6e27/attachment-0001.htm" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>pipermail/yt-users-spacepope.<wbr>org/attachments/20170708/<wbr>39ec6e27/attachment-0001.htm</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
<br>
<br>
------------------------------<br>
<br>
End of yt-users Digest, Vol 113, Issue 11<br>
******************************<wbr>***********<br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><span style="font-family:monospace,monospace">Salvatore</span></div></div></div></div>
</div></div>