1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
|
A Few Complex Plots
-------------------
The built-in plotting functionality covers the very simple use cases that are
most common. These scripts will demonstrate how to construct more complex
plots or publication-quality plots. In many cases these show how to make
multi-panel plots.
Multi-Width Image
~~~~~~~~~~~~~~~~~
This is a simple recipe to show how to open a dataset and then plot slices
through it at varying widths.
See :ref:`slice-plots` for more information.
.. yt_cookbook:: multi_width_image.py
.. _image-resolution-primer:
Varying the resolution of an image
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This illustrates the various parameters that control the resolution
of an image, including the (deprecated) refinement level, the size of
the :class:`~yt.visualization.fixed_resolution.FixedResolutionBuffer`,
and the number of pixels in the output image.
In brief, there are three parameters that control the final resolution,
with a fourth entering for particle data that is deposited onto a mesh
(i.e. pre-4.0). Those are:
1. ``buff_size``, which can be altered with
:meth:`~yt.visualization.plot_window.PlotWindow.set_buff_size`, which
is inherited by
:class:`~yt.visualization.plot_window.AxisAlignedSlicePlot`,
:class:`~yt.visualization.plot_window.OffAxisSlicePlot`,
:class:`~yt.visualization.plot_window.AxisAlignedProjectionPlot`, and
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`. This
controls the number of resolution elements in the
:class:`~yt.visualization.fixed_resolution.FixedResolutionBuffer`,
which can be thought of as the number of individually colored
squares (on a side) in a 2D image. ``buff_size`` can be set
after creating the image with
:meth:`~yt.visualization.plot_window.PlotWindow.set_buff_size`,
or during image creation with the ``buff_size`` argument to any
of the four preceding classes.
2. ``figure_size``, which can be altered with either
:meth:`~yt.visualization.plot_container.PlotContainer.set_figure_size`,
or can be set during image creation with the ``window_size`` argument.
This sets the size of the final image (including the visualization and,
if applicable, the axes and colorbar as well) in inches.
3. ``dpi``, i.e. the dots-per-inch in your final file, which can also
be thought of as the actual resolution of your image. This can
only be set on save via the ``mpl_kwargs`` parameter to
:meth:`~yt.visualization.plot_container.PlotContainer.save`. The
``dpi`` and ``figure_size`` together set the true resolution of your
image (final image will be ``dpi`` :math:`*` ``figure_size`` pixels on a
side), so if these are set too low, then your ``buff_size`` will not
matter. On the other hand, increasing these without increasing
``buff_size`` accordingly will simply blow up your resolution
elements to fill several real pixels.
4. (only for meshed particle data) ``n_ref``, the maximum number of
particles in a cell in the oct-tree allowed before it is refined
(removed in yt-4.0 as particle data is no longer deposited onto
an oct-tree). For particle data, ``n_ref`` effectively sets the
underlying resolution of your simulation. Regardless, for either
grid data or deposited particle data, your image will never be
higher resolution than your simulation data. In other words,
if you are visualizing a region 50 kpc across that includes
data that reaches a resolution of 100 pc, then there's no reason
to set a ``buff_size`` (or a ``dpi`` :math:`*` ``figure_size``) above
50 kpc/ 100 pc = 500.
The below script demonstrates how each of these can be varied.
.. yt_cookbook:: image_resolution.py
Multipanel with Axes Labels
~~~~~~~~~~~~~~~~~~~~~~~~~~~
This illustrates how to use a SlicePlot to control a multipanel plot. This
plot uses axes labels to illustrate the length scales in the plot.
See :ref:`slice-plots` and the
`Matplotlib AxesGrid Object <https://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html>`_
for more information.
.. yt_cookbook:: multiplot_2x2.py
The above example gives you full control over the plots, but for most
purposes, the ``export_to_mpl_figure`` method is a simpler option,
allowing us to make a similar plot as:
.. yt_cookbook:: multiplot_export_to_mpl.py
Multipanel with PhasePlot
~~~~~~~~~~~~~~~~~~~~~~~~~~~
This illustrates how to use PhasePlot in a multipanel plot.
See :ref:`how-to-make-2d-profiles` and the
`Matplotlib AxesGrid Object <https://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html>`_
for more information.
.. yt_cookbook:: multiplot_phaseplot.py
Time Series Multipanel
~~~~~~~~~~~~~~~~~~~~~~
This illustrates how to create a multipanel plot of a time series dataset.
See :ref:`projection-plots`, :ref:`time-series-analysis`, and the
`Matplotlib AxesGrid Object <https://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html>`_
for more information.
.. yt_cookbook:: multiplot_2x2_time_series.py
Multiple Slice Multipanel
~~~~~~~~~~~~~~~~~~~~~~~~~
This illustrates how to create a multipanel plot of slices along the coordinate
axes. To focus on what's happening in the x-y plane, we make an additional
Temperature slice for the bottom-right subpanel.
See :ref:`slice-plots` and the
`Matplotlib AxesGrid Object <https://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html>`_
for more information.
.. yt_cookbook:: multiplot_2x2_coordaxes_slice.py
Multi-Plot Slice and Projections
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This shows how to combine multiple slices and projections into a single image,
with detailed control over colorbars, titles and color limits.
See :ref:`slice-plots` and :ref:`projection-plots` for more information.
.. yt_cookbook:: multi_plot_slice_and_proj.py
.. _advanced-multi-panel:
Advanced Multi-Plot Multi-Panel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This 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.
See :ref:`slice-plots` and :ref:`projection-plots` for more information.
.. yt_cookbook:: multi_plot_3x2_FRB.py
Time Series Movie
~~~~~~~~~~~~~~~~~
This shows how to use matplotlib's animation framework with yt plots.
.. yt_cookbook:: matplotlib-animation.py
.. _cookbook-offaxis_projection:
Off-Axis Projection (an alternate method)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to take an image-plane line integral along an
arbitrary axis in a simulation. This uses alternate machinery than the
standard :ref:`PlotWindow interface <off-axis-projections>` to create an
off-axis projection as demonstrated in this
:ref:`recipe <cookbook-simple-off-axis-projection>`.
.. yt_cookbook:: offaxis_projection.py
Off-Axis Projection with a Colorbar (an alternate method)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe shows how to generate a colorbar with a projection of a dataset
from an arbitrary projection angle (so you are not confined to the x, y, and z
axes).
This uses alternate machinery than the standard
:ref:`PlotWindow interface <off-axis-projections>` to create an off-axis
projection as demonstrated in this
:ref:`recipe <cookbook-simple-off-axis-projection>`.
.. yt_cookbook:: offaxis_projection_colorbar.py
.. _thin-slice-projections:
Thin-Slice Projections
~~~~~~~~~~~~~~~~~~~~~~
This recipe is an example of how to project through only a given data object,
in this case a thin region, and then display the result.
See :ref:`projection-plots` and :ref:`available-objects` for more information.
.. yt_cookbook:: thin_slice_projection.py
Plotting Particles Over Fluids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to overplot particles on top of a fluid image.
See :ref:`annotate-particles` for more information.
.. yt_cookbook:: overplot_particles.py
Plotting Grid Edges Over Fluids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to overplot grid boxes on top of a fluid image.
Each level is represented with a different color from white (low refinement) to
black (high refinement). One can change the colormap used for the grids colors
by using the cmap keyword (or set it to None to get all grid edges as black).
See :ref:`annotate-grids` for more information.
.. yt_cookbook:: overplot_grids.py
Overplotting Velocity Vectors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to plot velocity vectors on top of a slice.
See :ref:`annotate-velocity` for more information.
.. yt_cookbook:: velocity_vectors_on_slice.py
Overplotting Contours
~~~~~~~~~~~~~~~~~~~~~
This is a simple recipe to show how to open a dataset, plot a slice through it,
and add contours of another quantity on top.
See :ref:`annotate-contours` for more information.
.. yt_cookbook:: contours_on_slice.py
Simple Contours in a Slice
~~~~~~~~~~~~~~~~~~~~~~~~~~
Sometimes it is useful to plot just a few contours of a quantity in a
dataset. This shows how one does this by first making a slice, adding
contours, and then hiding the colormap plot of the slice to leave the
plot containing only the contours that one has added.
See :ref:`annotate-contours` for more information.
.. yt_cookbook:: simple_contour_in_slice.py
Styling Radial Profile Plots
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates a method of calculating radial profiles for several
quantities, styling them and saving out the resultant plot.
See :ref:`how-to-make-1d-profiles` for more information.
.. yt_cookbook:: radial_profile_styles.py
Customized Profile Plot
~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to create a fully customized 1D profile object
using the :func:`~yt.data_objects.profiles.create_profile` function and then
create a :class:`~yt.visualization.profile_plotter.ProfilePlot` using the
customized profile. This illustrates how a ``ProfilePlot`` created this way
inherits the properties of the profile it is constructed from.
See :ref:`how-to-make-1d-profiles` for more information.
.. yt_cookbook:: customized_profile_plot.py
Customized Phase Plot
~~~~~~~~~~~~~~~~~~~~~
Similar to the recipe above, this demonstrates how to create a fully customized
2D profile object using the :func:`~yt.data_objects.profiles.create_profile`
function and then create a :class:`~yt.visualization.profile_plotter.PhasePlot`
using the customized profile object. This illustrates how a ``PhasePlot``
created this way inherits the properties of the profile object from which it
is constructed. See :ref:`how-to-make-2d-profiles` for more information.
.. yt_cookbook:: customized_phase_plot.py
.. _cookbook-camera_movement:
Moving a Volume Rendering Camera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In this recipe, we move a camera through a domain and take multiple volume
rendering snapshots. This recipe uses an unstructured mesh dataset (see
:ref:`unstructured_mesh_rendering`), which makes it easier to visualize what
the Camera is doing, but you can manipulate the Camera for other dataset types
in exactly the same manner.
See :ref:`camera_movement` for more information.
.. yt_cookbook:: camera_movement.py
Volume Rendering with Custom Camera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In this recipe we modify the :ref:`cookbook-simple_volume_rendering` recipe to
use customized camera properties. See :ref:`volume_rendering` for more
information.
.. yt_cookbook:: custom_camera_volume_rendering.py
.. _cookbook-custom-transfer-function:
Volume Rendering with a Custom Transfer Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In this recipe we modify the :ref:`cookbook-simple_volume_rendering` recipe to
use customized camera properties. See :ref:`volume_rendering` for more
information.
.. yt_cookbook:: custom_transfer_function_volume_rendering.py
.. _cookbook-sigma_clip:
Volume Rendering with Sigma Clipping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In this recipe we output several images with different values of sigma_clip
set in order to change the contrast of the resulting image. See
:ref:`sigma_clip` for more information.
.. yt_cookbook:: sigma_clip.py
Zooming into an Image
~~~~~~~~~~~~~~~~~~~~~
This is a recipe that takes a slice through the most dense point, then creates
a bunch of frames as it zooms in. It's important to note that this particular
recipe is provided to show how to be more flexible and add annotations and the
like -- the base system, of a zoomin, is provided by the "yt zoomin" command on
the command line.
See :ref:`slice-plots` and :ref:`callbacks` for more information.
.. yt_cookbook:: zoomin_frames.py
.. _cookbook-various_lens:
Various Lens Types for Volume Rendering
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This example illustrates the usage and feature of different lenses for volume rendering.
.. yt_cookbook:: various_lens.py
.. _cookbook-opaque_rendering:
Opaque Volume Rendering
~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to make semi-opaque volume renderings, but also
how to step through and try different things to identify the type of volume
rendering you want.
See :ref:`opaque_rendering` for more information.
.. yt_cookbook:: opaque_rendering.py
Volume Rendering Multiple Fields
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can render multiple fields by adding new ``VolumeSource`` objects to the
scene for each field you want to render.
.. yt_cookbook:: render_two_fields.py
.. _cookbook-amrkdtree_downsampling:
Downsampling Data for Volume Rendering
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to downsample data in a simulation to speed up
volume rendering.
See :ref:`volume_rendering` for more information.
.. yt_cookbook:: amrkdtree_downsampling.py
.. _cookbook-volume_rendering_annotations:
Volume Rendering with Bounding Box and Overlaid Grids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to overplot a bounding box on a volume rendering
as well as overplotting grids representing the level of refinement achieved
in different regions of the code.
See :ref:`volume_rendering_annotations` for more information.
.. yt_cookbook:: rendering_with_box_and_grids.py
Volume Rendering with Annotation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to write the simulation time, show an
axis triad indicating the direction of the coordinate system, and show
the transfer function on a volume rendering. Please note that this
recipe relies on the old volume rendering interface. While one can
continue to use this interface, it may be incompatible with some of the
new developments and the infrastructure described in :ref:`volume_rendering`.
.. yt_cookbook:: vol-annotated.py
.. _cookbook-render_two_fields_tf:
Volume Rendering Multiple Fields And Annotation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe shows how to display the transfer functions when rendering multiple
fields in a volume render.
.. yt_cookbook:: render_two_fields_tf.py
.. _cookbook-vol-points:
Volume Rendering with Points
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to make a volume rendering composited with point
sources. This could represent star or dark matter particles, for example.
.. yt_cookbook:: vol-points.py
.. _cookbook-vol-lines:
Volume Rendering with Lines
~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to make a volume rendering composited with line
sources.
.. yt_cookbook:: vol-lines.py
Plotting Streamlines
~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to display streamlines in a simulation. (Note:
streamlines can also be queried for values!)
See :ref:`streamlines` for more information.
.. yt_cookbook:: streamlines.py
Plotting Isocontours
~~~~~~~~~~~~~~~~~~~~
This recipe demonstrates how to extract an isocontour and then plot it in
matplotlib, coloring the surface by a second quantity.
See :ref:`surfaces` for more information.
.. yt_cookbook:: surface_plot.py
Plotting Isocontours and Streamlines
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This recipe plots both isocontours and streamlines simultaneously. Note that
this will not include any blending, so streamlines that are occluded by the
surface will still be visible.
See :ref:`streamlines` and :ref:`surfaces` for more information.
.. yt_cookbook:: streamlines_isocontour.py
|