[yt-users] multiplot with multiple datasets

Matthew Turk matthewturk at gmail.com
Wed Mar 23 21:07:27 PDT 2011


Hi JC,

On Tue, Mar 22, 2011 at 9:26 PM, Jean-Claude Passy <jcpassy at gmail.com> wrote:
> Hi again,
>
> I am sorry to bring it up again but I have two very last questions I would
> like to ask you:
>
> 1) I have created a multiplot using Christine's script in which each column
> uses the same colorbar. Therefore, I end up with two identical colorbars
> under each column. It is possible to have only one colorbar stretched over
> the two columns instead ?

This will require some work; you'll need to figure out how to
construct an axes by hand and then spread it across.  It's not
terribly complicated in principle, but I've found it to be difficult
in practice.  (I use the term "axes" here to refer to matplotlib axes
objects, which are essentially regions inside the figure that gets
saved out.)

When you create a colorbar, you can supply to it two items.  One of
these is the "axes" object and the other is the mappable, from which
the colorbar draws its values (and to which it applies colors.)  You
can create by hand axes objects by specifying regions in your figure
that you want to mark off as being part of the axes (these can be
overlapping, as well, but that leads to issues with stacking and
compositing.)  This can be done with either direct instantiation of
matplotlib.axes.Axes objects (supplying a Figure object) or with the
method add_axes that hangs off a Figure object.

Once you have created an axes that subtends the desired portion of the
Figure, you can then insert a colorbar into it.

This gets complicated really fast, and we're already way past the
point where I'm comfortable ... (this is one reason the plotting
functionality in yt is generally quite basic in terms of how the plots
are laid out on a page.)

Your best bet, in my view, is to either modify Christine's script to
change how it creates the colorbars, or to simply back up and try
using the axes_grid functionality in Matplotlib.  This allows for
different methods of constructing colorbars and all of that.
Alternately, it might be helpful to pose your question on the
matplotlib users mailing list; I'm happy to help compose it in a way
that'll make sense, given how yt works behind-the-scenes quite a bit
with the matplotlib API.

>
> 2) I added the velocity field to the slice. Is there an argument allowing
> different scaling of the velocity vector ? Also, it there a way give the
> velocity vector scale on the figure ? All I was able to find in the
> documentation was about the argument 'factor' constraining the number of
> cells skipped.

Unfortunately, there is not as of yet.  I think there are some
interesting ways of representing this in the internal matplotlib
mechanisms.  If you look at the help for matplotlib.axes.Axes.quiver
(i.e., python -c "import matplotlib;help(matplotlib.axes.Axes.quiver")
you can see that there are issues of internal data units and length.
To add this, you'd have to add a scaling factor to the QuiverCallback
in yt/visualization/plot_modifications.py and then string it through
to the VelocityCallback and MagneticFIeldCallback.

I'd be happy to merge in changes to this end; you should be able to
fork on BitBucket:

http://hg.enzotools.org/yt/fork

and then if you think you have it nicely working, we'll pull the changes in:

http://hg.enzotools.org/yt/pull

Best wishes, and sorry this email has been full of disappointing news.
 Maybe somebody else has a better handle on one or both of these
items?

-Matt

>
> Thanks again for your help,
>
> JC
>
>
> On 22/03/11 18:40, Jean-Claude Passy wrote:
>>
>> Thanks Matt (and Christine), it worked perfectly.
>>
>> I like your suggestion a lot but I think we should rather call it the
>> "RETURN of the Particle" ;-)
>>
>> Cheers,
>>
>> JC
>>
>> On 22/03/11 16:49, Matthew Turk wrote:
>>>
>>> Hi JC,
>>>
>>> On Mon, Mar 21, 2011 at 9:57 PM, Jean-Claude Passy<jcpassy at gmail.com>
>>> wrote:
>>>>
>>>> Hi Christine,
>>>>
>>>> thanks a lot for your script, it does exactly what I need.
>>>>
>>>> The last thing I would need is being able to overplot the particles
>>>> positions and the velocity field. I tried to add the following after
>>>> creating the slice:
>>>>
>>>> ######################################################
>>>> p = pc0.plots[-1].modify["velocity"]() p =
>>>> pc0.plots[-1].modify["particles"](width=10, p_size=10.0, col='g')
>>>> ######################################################
>>>>
>>>> Although it does not make the code break, the slices remain unchanged.
>>>
>>> Sorry to jump in, but if you do this, you should be able to call
>>> either pc0.plots[-1]._redraw_image() or, if thatm odifies the color
>>> bars (it might, depending on how the script is written) you can call
>>> pc0.plots[-1]._run_callbacks() to manually run them.  The reason that
>>> the particles don't get plotted immediately is because they're
>>> supposed to be 'view independent' so they don't get drawn until the
>>> image is ready to be written out.
>>>
>>> Hope that works,
>>>
>>> Matt
>>>
>>> PS I was just thinking earlier today that one of your first emails to
>>> me, years ago, was with the subject line "The Particle Strikes Back."
>>> I guess this one could be "Revenge of the Particle"?
>>>
>>>> Do you have any idea how to make it work ? If not, I will follow
>>>> Britton's
>>>> advice and dig a little bit more into the more complex
>>>> yt-advanced-plotting
>>>> rep.
>>>>
>>>> Thanks a lot,
>>>>
>>>> JC
>>>>
>>>>
>>>> On 22/03/11 06:24, Christine Simpson wrote:
>>>>
>>>> Hi JC,
>>>>
>>>> Matt says the yt developers are working on some more sophisticated
>>>> imaging capabilities, but in the meantime, this script does something
>>>> close to what you want.  It's a bit cumbersome, but it may be helpful to
>>>> you.  It plots density slices in the x,y,z directions for two different
>>>> datasets in side-by-side columns.  In general, I think you just need to
>>>> set up separate plot collections for each dataset you want to plot.  The
>>>> tricky part is getting the colorbars to work; the way i've done it
>>>> below, you can in can have different colorbars for the two different
>>>> columns.:
>>>>
>>>> from yt.mods import * # set up our namespace
>>>> import matplotlib.colorbar as cb
>>>>
>>>>
>>>> fn0 = "DD0007/output_0007"
>>>> fn1 = "DD0010/output_0010"
>>>>
>>>>
>>>> pf0 = load(fn0) # load data
>>>> pf1 = load(fn1)
>>>>
>>>> orient = 'horizontal'
>>>> fig, axes, colorbars = get_multi_plot( 2, 3, colorbar=orient, bw = 4)
>>>>
>>>> pc0 = PlotCollection(pf0)
>>>> pc1 = PlotCollection(pf1)
>>>>
>>>>
>>>> for ax in range(3):
>>>>
>>>>      p = pc0.add_slice("Density", ax, figure = fig, axes = axes[ax][0],
>>>> use_colorbar=False)
>>>>      p.set_cmap("bds_highcontrast")
>>>>      p.set_zlim(10**(-27),10**(-25))
>>>>
>>>>
>>>>      p = pc1.add_slice("Density", ax, figure=fig, axes=axes[ax][1],
>>>> use_colorbar=False)
>>>>      p.set_cmap("bds_highcontrast")
>>>>      p.set_zlim(10**(-30),10**(-25))
>>>>
>>>>
>>>> pc0.set_width(25.0, 'kpc')
>>>> pc1.set_width(25.0, 'kpc')
>>>>
>>>>
>>>> zip_plot = zip(pc0.plots,pc1.plots)
>>>> all_plots = [zip_plot[i][j] for i in range(3) for j in range(2)]
>>>>
>>>>
>>>> for p, cax in zip(all_plots, colorbars):
>>>>
>>>>      cbar = cb.Colorbar(cax, p.image, orientation=orient)
>>>>
>>>>      p.colorbar = cbar
>>>>      p._autoset_label()
>>>>
>>>>
>>>> fig.savefig("Density_before_after_reion")
>>>>
>>>>
>>>>
>>>> On Sun, 2011-03-20 at 17:06 -0700, Matthew Turk wrote:
>>>>
>>>> Hi Chris and JC,
>>>>
>>>> You're right; they are not up to date in the build.  It was a mistake
>>>> in how I built the docs last.  I updated all the *API* content, but
>>>> not the content of the *recipes*.  When I get back to my desk tonight
>>>> (I'm out enjoying some Sunday afternoon recreation time right now) I
>>>> will rebuild the docs, but I'll build from the development branch so
>>>> they will reflect the upcoming 2.1 release in a few minor ways, like
>>>> minor shifts in the light cone API.  Sam's release manager for 2.1,
>>>> and last I heard from him he's planning on late this week or early
>>>> next.
>>>>
>>>> Also, JC, Britton, Sam and Jeff have been working on making it easier
>>>> to do more complicated things with montages and compositing of
>>>> arbitrary images.  They might be able to chime in with more; multiplot
>>>> is kind of a sledge hammer and they're putting the finishing touches
>>>> on their nice set of drill bits and screw drivers.
>>>>
>>>> Best,
>>>>
>>>> Matt
>>>>
>>>> On Sun, Mar 20, 2011 at 4:59 PM,<chris.m.malone at gmail.com>   wrote:
>>>>
>>>> I should say, the recipe is up to date (in the hg repository), but the
>>>> Cookbook website is not. Same goes for the regular Multiplot recipe.
>>>>
>>>> Matt, could you update these?
>>>>
>>>> Chris
>>>>
>>>> On Mar 20, 2011 7:47pm, chris.m.malone at gmail.com wrote:
>>>>
>>>> Hi Jean-Claude,
>>>>
>>>> Some of the recipes in the Cookbook are a bit outdated - for example,
>>>> module names like "raven" have been replaced with more meaningful names.
>>>> Actually, now the get_multi_plot() method lives in the plot_collection
>>>> module, which is automatically loaded into the namespace when you `from
>>>> yt.mods import *`. In other words, change the `raven.get_mult_plot(...)`
>>>> to
>>>> just `get_multi_plot(...)` and it should work ok, although I haven't
>>>> tested
>>>> this.
>>>>
>>>> Chris
>>>>
>>>>
>>>> On Mar 20, 2011 7:27pm, Jean-Claude Passy jcpassy at gmail.com>   wrote:
>>>>
>>>>
>>>>
>>>>
>>>> Hi all,
>>>>
>>>>
>>>>
>>>> I would like to create a multi plot equivalent to the procedure
>>>> described in the Cookbook (Multi plot 3x2) BUT with
>>>> different datasets (1 slice for 1 dataset).
>>>>
>>>>
>>>>
>>>> The first issue I am encountering is that the module raven is not
>>>> detected:
>>>>
>>>>
>>>>
>>>> #############################################################
>>>>
>>>> Traceback (most recent call last):
>>>>    File "/rpod2/jcpassy/Enzo/python/MultiPlot.py", line 20,
>>>> in
>>>>      fig, axes, colorbars = raven.get_multi_plot( 2, 4,
>>>> colorbar=orient, bw = 4)
>>>> NameError: name 'raven' is not defined
>>>> #############################################################
>>>>
>>>>
>>>>
>>>> Then, is there a specific description somewhere of how to do a multi
>>>> plot with different datasets ?
>>>>
>>>>
>>>>
>>>> Thanks a lot for your help,
>>>>
>>>>
>>>>
>>>> JC
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>>
>>> _______________________________________________
>>> 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
>
> _______________________________________________
> 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