[yt-svn] commit/cookbook: jsoishi: added script to do a multiplot using a fixed resolution buffer.
Bitbucket
commits-noreply at bitbucket.org
Fri Dec 9 10:25:48 PST 2011
1 new commit in cookbook:
https://bitbucket.org/yt_analysis/cookbook/changeset/c12995238a35/
changeset: c12995238a35
user: jsoishi
date: 2011-12-09 19:25:28
summary: added script to do a multiplot using a fixed resolution buffer.
affected #: 1 file
diff -r 7cec997d1994a91e82e449abbd2c2b25015efd6a -r c12995238a35103bbf4f81f0b4f8c8c653426b09 recipes/multi_plot_3x2_FRB.py
--- /dev/null
+++ b/recipes/multi_plot_3x2_FRB.py
@@ -0,0 +1,73 @@
+"""
+This is a simple recipe to illustrate the
+:func:`~yt.visualization.plot_collection.get_multi_plot`
+functionality. It produces a series of slices of multiple fields with
+different color maps and zlimits, and makes use of the
+FixedResolutionBuffer. While this is more complex than the equivalent
+plot collection-based solution, it allows for a *lot* more
+flexibility. Every part of the script uses matplotlib commands,
+allowing its full power to be exercised.
+"""
+from yt.mods import * # set up our namespace
+import matplotlib.colorbar as cb
+from matplotlib.colors import LogNorm
+
+fn = "RedshiftOutput0005" # parameter file to load
+
+
+pf = load(fn) # load data
+
+# set up our Fixed Resolution Buffer parameters: a width, resolution, and center
+width = 7./pf['mpc']
+res = [1000, 1000]
+c = pf.h.find_max('Density')[1]
+# get_multi_plot returns a containing figure, a list-of-lists of axes
+# into which we can place plots, and some axes that we'll put
+# colorbars.
+
+# it accepts: # of x-axis plots, # of y-axis plots, and how the
+# colorbars are oriented (this also determines where they go: below
+# in the case of 'horizontal', on the right in the case of
+# 'vertical'), bw is the base-width in inches (4 is about right for
+# most cases)
+
+orient = 'horizontal'
+fig, axes, colorbars = get_multi_plot( 2, 3, colorbar=orient, bw = 6)
+
+# Now we follow the method of "multi_plot.py" but we're going to iterate
+# over the columns, which will become axes of slicing.
+plots = []
+for ax in range(3):
+ sli = pf.h.slice(ax,c[ax])
+ frb = sli.to_frb(width, res, center=c, periodic=True)
+ den_axis = axes[ax][0]
+ temp_axis = axes[ax][1]
+
+ # here, we turn off the axes labels and ticks, but you could
+ # customize further.
+ for ax in (den_axis, temp_axis):
+ ax.xaxis.set_visible(False)
+ ax.yaxis.set_visible(False)
+
+ plots.append(den_axis.imshow(frb['Density'], norm=LogNorm()))
+ plots[-1].set_clim((5e-32, 1e-29))
+ plots[-1].set_cmap("bds_highcontrast")
+
+ plots.append(temp_axis.imshow(frb['Temperature'], norm=LogNorm()))
+ plots[-1].set_clim((1e3, 3e4))
+ plots[-1].set_cmap("hot")
+
+# Each 'cax' is a colorbar-container, into which we'll put a colorbar.
+# the zip command creates triples from each element of the three lists
+# . Note that it cuts off after the shortest iterator is exhausted,
+# in this case, titles.
+titles=[r'$\mathrm{Density}\ (\mathrm{g\ cm^{-3}})$', r'$\mathrm{Temperature}\ (\mathrm{K})$']
+for p, cax, t in zip(plots, colorbars,titles):
+ # Now we make a colorbar, using the 'image' we stored in plots
+ # above. note this is what is *returned* by the imshow method of
+ # the plots.
+ cbar = fig.colorbar(p, cax=cax, orientation=orient)
+ cbar.set_label(t)
+
+# And now we're done!
+fig.savefig("%s_3x2" % pf)
Repository URL: https://bitbucket.org/yt_analysis/cookbook/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list