yt.visualization.eps_writer module

class yt.visualization.eps_writer.DualEPS(figsize=12, 12)[source]

Bases: object

arrow(size=0.2, label='', loc=(0.05, 0.08), labelloc='top', color=<pyx.color.cmyk object>, linewidth=<pyx.style.linewidth object>, rotation=0.0)[source]

Draws an arrow in the current figure

Parameters
  • size (float) – Length of arrow (base to tip) in units of the figure size.

  • label (string) – Annotation label of the arrow.

  • loc (tuple of floats) – Location of the left hand side of the arrow in units of the figure size.

  • rotation (float) – Orientation angle of the arrow in units of degrees

  • labelloc (string) – Location of the label with respect to the line. Can be “top” or “bottom”

  • color (pyx.color.*.*) – Color of the arrow. Example: pyx.color.cymk.white

  • linewidth (pyx.style.linewidth.*) – Width of the arrow. Example: pyx.style.linewidth.normal

Examples

>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
>>> d.insert_image("arrow_image.jpg")
>>> d.arrow(size=0.2, label="Black Hole!", loc=(0.05, 0.1))
>>> d.save_fig()
axis_box(xrange=0, 1, yrange=0, 1, xlabel='', ylabel='', xlog=False, ylog=False, xdata=None, ydata=None, tickcolor=None, bare_axes=False, pos=0, 0, xaxis_side=0, yaxis_side=0, size=None)[source]

Draws an axis box in the figure.

Parameters
  • xrange (tuple of floats) – The min and max of the x-axis

  • yrange (tuple of floats) – The min and max of the y-axis

  • xlabel (string) – Label for the x-axis

  • ylabel (string) – Label for the y-axis

  • xlog (boolean) – Flag to use a logarithmic x-axis

  • ylog (boolean) – Flag to use a logarithmic y-axis

  • tickcolor (pyx.color.*.*) – Color for the tickmarks. Example: pyx.color.cmyk.black

  • bare_axes (boolean) – Set to true to have no annotations or tick marks on all of the axes.

  • pos (tuple of floats) – (x,y) position in centimeters of the origin in the figure

  • xaxis_side (integer) – Set to 0 for the x-axis annotations to be on the left. Set to 1 to print them on the right side.

  • yaxis_side (integer) – Set to 0 for the y-axis annotations to be on the bottom. Set to 1 to print them on the top.

  • size (tuple of floats) – Size of axis box in units of figsize

Examples

>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
>>> d.save_fig()
axis_box_yt(plot, units=None, bare_axes=False, tickcolor=None, xlabel=None, ylabel=None, **kwargs)[source]

Wrapper around DualEPS.axis_box to automatically fill in the axis ranges and labels from a yt plot.

This also accepts any parameters that DualEPS.axis_box takes.

Parameters
  • plot (yt.visualization.plot_window.PlotWindow) – yt plot on which the axes are based.

  • units (string) – Unit description that overrides yt’s unit description. Only affects the axis label.

  • bare_axes (boolean) – Set to true to have no annotations or tick marks on all of the axes.

Examples

>>> p = SlicePlot(ds, 0, "density")
>>> d = DualEPS()
>>> d.axis_box_yt(p)
>>> d.save_fig()
circle(radius=0.2, loc=(0.5, 0.5), color=<pyx.color.cmyk object>, linewidth=<pyx.style.linewidth object>)[source]

Draws a circle in the current figure.

Parameters
  • radius (float) – Radius of the circle in units of figsize

  • loc (tuple of floats) – Location of the circle’s center in units of figsize

  • color (pyx.color.*.*) – Color of the circle stroke. Example: pyx.color.cmyk.white

  • linewidth (pyx.style.linewidth.*) – Width of the circle stroke width. Example: pyx.style.linewidth.normal

Examples

>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
>>> d.insert_image("image.jpg")
>>> d.circle(radius=0.1, color=pyx.color.cmyk.Red)
>>> d.save_fig()
colorbar(name, zrange=0, 1, label='', log=False, tickcolor=None, orientation='right', pos=None, shrink=1.0)[source]

Places a colorbar adjacent to the current figure.

Parameters
  • name (string) – name of the (matplotlib) colormap to use

  • zrange (tuple of floats) – min and max of the colorbar’s range

  • label (string) – colorbar label

  • log (boolean) – Flag to use a logarithmic scale

  • tickcolor (pyx.color.*.*) – Color for the tickmarks. Example: pyx.color.cmyk.black

  • orientation (string) – Placement of the colorbar. Can be “left”, “right”, “top”, or “bottom”.

  • pos (list of floats) – (x,y) position of the origin of the colorbar in centimeters.

  • shrink (float) – Factor to shrink the colorbar’s size. A value of 1 means the colorbar will have a height / width of the figure.

Examples

>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
>>> d.insert_image("image.jpg")
>>> d.colorbar(
...     "hot", xrange=(1e-2, 1e-4), log=True, label="Density [cm$^{-3}$]"
... )
>>> d.save_fig()
colorbar_yt(plot, field=None, cb_labels=None, **kwargs)[source]

Wrapper around DualEPS.colorbar to take information from a yt plot.

Accepts all parameters that DualEPS.colorbar takes.

Parameters
  • plot (A yt plot) – yt plot from which the information is taken.

  • cb_labels (list of labels for the colorbars. List should be the same) – size as the number of colorbars used. Should be passed into this function by either the singleplot or multiplot api.

Examples

>>> p = SlicePlot(ds, 0, "density")
>>> p.hide_colorbar()
>>> d = DualEPS()
>>> d.axis_box_yt(p)
>>> d.insert_image_yt(p)
>>> d.colorbar_yt(p)
>>> d.save_fig()
hello_world()[source]

A simple test.

insert_image(filename, pos=0, 0, size=None)[source]

Inserts a JPEG file in the figure.

Parameters
  • filename (string) – Name of the JPEG file

  • pos (tuple of floats) – Position of the origin of the image in centimeters

  • size (tuple of flots) – Size of image in units of figsize

Examples

>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
>>> d.insert_image("image.jpg")
>>> d.save_fig()
insert_image_yt(plot, field=None, pos=0, 0, scale=1.0)[source]

Inserts a bitmap taken from a yt plot.

Parameters
  • plot (yt.visualization.plot_window.PlotWindow) – yt plot that provides the image

  • pos (tuple of floats) – Position of the origin of the image in centimeters.

Examples

>>> p = SlicePlot(ds, 0, "density")
>>> d = DualEPS()
>>> d.axis_box_yt(p)
>>> d.insert_image_yt(p)
>>> d.save_fig()

Notes

For best results, set use_colorbar=False when creating the yt image.

return_field(plot)[source]
save_fig(filename='test', format='eps', resolution=250)[source]

Saves current figure to a file.

Parameters
  • filename (string) – Name of the saved file without the extension.

  • format (string) – Format type. Can be “eps” or “pdf”

Examples

>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
scale_line(size=0.2, label='', loc=(0.05, 0.08), labelloc='top', color=<pyx.color.cmyk object>, linewidth=<pyx.style.linewidth object>)[source]

Draws a scale line in the current figure.

Parameters
  • size (float) – Length of the scale line in units of the figure size.

  • label (string) – Annotation label of the scale line.

  • loc (tuple of floats) – Location of the left hand side of the scale line in units of the figure size.

  • labelloc (string) – Location of the label with respect to the line. Can be “top” or “bottom”

  • color (pyx.color.*.*) – Color of the scale line. Example: pyx.color.cymk.white

  • linewidth (pyx.style.linewidth.*) – Width of the scale line. Example: pyx.style.linewidth.normal

Examples

>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
>>> d.insert_image("image.jpg")
>>> d.scale_line(size=0.2, label="1 kpc", loc=(0.05, 0.1))
>>> d.save_fig()
title_box(text, color=<pyx.color.cmyk object>, bgcolor=<pyx.color.cmyk object>, loc=(0.02, 0.98), halign=<pyx.text.halign object>, valign=<pyx.text.valign object>, text_opts=None)[source]

Inserts a box with text in the current figure.

Parameters
  • text (string) – String to insert in the textbox.

  • color (pyx.color.*.*) – Color of the text. Example: pyx.color.cmyk.black

  • bgcolor (pyx.color.*.*) – Color of the textbox background. Example: pyx.color.cmyk.white

  • loc (tuple of floats) – Location of the textbox origin in units of the figure size.

  • halign (pyx.text.halign.*) – Horizontal alignment of the text. Example: pyx.text.halign.left

  • valign (pyx.text.valign.*) – Vertical alignment of the text. Example: pyx.text.valign.top

Examples

>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
>>> d.insert_image("image.jpg")
>>> d.title_box("Halo 1", loc=(0.05, 0.95))
>>> d.save_fig()
yt.visualization.eps_writer.convert_frac_to_tex(string)[source]
yt.visualization.eps_writer.multiplot(ncol, nrow, yt_plots=None, fields=None, images=None, xranges=None, yranges=None, xlabels=None, ylabels=None, xdata=None, ydata=None, colorbars=None, shrink_cb=0.95, figsize=8, 8, margins=0, 0, titles=None, savefig=None, format='eps', yt_nocbar=False, bare_axes=False, xaxis_flags=None, yaxis_flags=None, cb_flags=None, cb_location=None, cb_labels=None)[source]

Convenience routine to create a multi-panel figure from yt plots or JPEGs. The images are first placed from the origin, and then bottom-to-top and left-to-right.

Parameters
  • ncol (integer) – Number of columns in the figure.

  • nrow (integer) – Number of rows in the figure.

  • yt_plots (list of yt plot instances) – yt plots to include in the figure.

  • images (list of strings) – JPEG filenames to include in the figure.

  • xranges (list of tuples) – The min and max of the x-axes

  • yranges (list of tuples) – The min and max of the y-axes

  • xlabels (list of strings) – Labels for the x-axes

  • ylabels (list of strings) – Labels for the y-axes

  • colorbars (list of dicts) – Dicts that describe the type of colorbar to be used in each figure. Use the function return_colormap() to create these dicts.

  • shrink_cb (float) – Factor by which the colorbar is shrunk.

  • figsize (tuple of floats) – The width and height of a single figure in centimeters.

  • margins (tuple of floats) – The horizontal and vertical margins between panels in centimeters.

  • titles (list of strings) – Titles that are placed in textboxes in each panel.

  • savefig (string) – Name of the saved file without the extension.

  • format (string) – File format of the figure. eps or pdf accepted.

  • yt_nocbar (boolean) – Flag to indicate whether or not colorbars are created.

  • bare_axes (boolean) – Set to true to have no annotations or tick marks on all of the axes.

  • cb_flags (list of booleans) – Flags for each plot to have a colorbar or not.

  • cb_location (list of strings) – Strings to control the location of the colorbar (left, right, top, bottom)

  • cb_labels (list of labels for the colorbars. List should be the same) – size as the number of colorbars used.

Examples

>>> images = ["density.jpg", "hi_density.jpg", "entropy.jpg", "special.jpg"]
>>> cbs = []
>>> cbs.append(return_colormap("arbre", "Density [cm$^{-3}$]", (0, 10), False))
>>> cbs.append(return_colormap("kelp", "HI Density", (0, 5), False))
>>> cbs.append(return_colormap("hot", r"Entropy [K cm$^2$]", (1e-2, 1e6), True))
>>> cbs.append(return_colormap("Spectral", "Stuff$_x$!", (1, 300), True))
>>> mp = multiplot(
...     2,
...     2,
...     images=images,
...     margins=(0.1, 0.1),
...     titles=["1", "2", "3", "4"],
...     xlabels=["one", "two"],
...     ylabels=None,
...     colorbars=cbs,
...     shrink_cb=0.95,
... )
>>> mp.scale_line(label="$r_{vir}$", labelloc="top")
>>> mp.save_fig("multiplot")

Notes

If given both yt_plots and images, this will get preference to the yt plots.

yt.visualization.eps_writer.multiplot_yt(ncol, nrow, plots, fields=None, **kwargs)[source]

Wrapper for multiplot that takes a yt PlotWindow

Accepts all parameters used in multiplot.

Parameters
  • ncol (integer) – Number of columns in the figure.

  • nrow (integer) – Number of rows in the figure.

  • plots (PlotWindow instance, PhasePlot instance, or list of plots) – yt plots to be used.

Examples

>>> p1 = SlicePlot(ds, 0, "density")
>>> p1.set_width(10, "kpc")
>>> p2 = SlicePlot(ds, 0, "temperature")
>>> p2.set_width(10, "kpc")
>>> p2.set_colormap("temperature", "hot")
>>> sph = ds.sphere(ds.domain_center, (10, "kpc"))
>>> p3 = PhasePlot(
...     sph, "radius", "density", "temperature", weight_field="cell_mass"
... )
>>> p4 = PhasePlot(sph, "radius", "density", "pressure", "cell_mass")
>>> mp = multiplot_yt(
...     2,
...     2,
...     [p1, p2, p3, p4],
...     savefig="yt",
...     shrink_cb=0.9,
...     bare_axes=True,
...     yt_nocbar=False,
...     margins=(0.5, 0.5),
... )
yt.visualization.eps_writer.pyxize_label(string)[source]
yt.visualization.eps_writer.return_cmap(cmap=None, label='', range=0, 1, log=False)[source]
yt.visualization.eps_writer.return_colormap(cmap=None, label='', range=0, 1, log=False)[source]

Returns a dict that describes a colorbar. Exclusively for use with multiplot.

Parameters
  • cmap (string) – name of the (matplotlib) colormap to use

  • label (string) – colorbar label

  • range (tuple of floats) – min and max of the colorbar’s range

  • log (boolean) – Flag to use a logarithmic scale

Examples

>>> cb = return_colormap("arbre", "Density [cm$^{-3}$]", (0, 10), False)
yt.visualization.eps_writer.single_plot(plot, field=None, figsize=12, 12, cb_orient='right', bare_axes=False, savefig=None, colorbar=True, file_format='eps', **kwargs)[source]

Wrapper for DualEPS routines to create a figure directly from a yt plot. Calls insert_image_yt, axis_box_yt, and colorbar_yt.

Parameters
  • plot (yt.visualization.plot_window.PlotWindow) – yt plot that provides the image and metadata

  • figsize (tuple of floats) – Size of the figure in centimeters.

  • cb_orient (string) – Placement of the colorbar. Can be “left”, “right”, “top”, or “bottom”.

  • bare_axes (boolean) – Set to true to have no annotations or tick marks on all of the axes.

  • savefig (string) – Name of the saved file without the extension.

  • colorbar (boolean) – Set to true to include a colorbar

  • file_format (string) – Format type. Can be “eps” or “pdf”

Examples

>>> p = SlicePlot(ds, 0, "density")
>>> p.set_width(0.1, "kpc")
>>> single_plot(p, savefig="figure1")