Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: ProjectionPlot as a factory function #3450

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions doc/source/analyzing/fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,23 @@ this will be handled automatically:
.. code-block:: python

prj = yt.ProjectionPlot(
ds, "z", ("gas", "velocity_los"), weight_field=("gas", "density")
ds,
normal="z",
fields=("gas", "velocity_los"),
weight_field=("gas", "density"),
)

Which, because the axis is ``"z"``, will give you the same result if you had
projected the ``"velocity_z"`` field. This also works for off-axis projections:
projected the ``"velocity_z"`` field. This also works for off-axis projections,
using an arbitrary normal vector

.. code-block:: python

prj = yt.OffAxisProjectionPlot(
ds, [0.1, -0.2, 0.3], ("gas", "velocity_los"), weight_field=("gas", "density")
prj = yt.ProjectionPlot(
ds,
normal=[0.1, -0.2, 0.3],
fields=("gas", "velocity_los"),
weight_field=("gas", "density"),
)


Expand Down
2 changes: 1 addition & 1 deletion doc/source/analyzing/objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Alternatively, we could create a sphere object of radius 1 kpc on location

After an object has been created, it can be used as a data_source to certain
tasks like ``ProjectionPlot`` (see
:class:`~yt.visualization.plot_window.ProjectionPlot`), one can compute the
:func:`~yt.visualization.plot_window.ProjectionPlot`), one can compute the
bulk quantities associated with that object (see :ref:`derived-quantities`),
or the data can be examined directly. For example, if you want to figure out
the temperature at all indexed locations in the central sphere of your
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook/complex_plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ with a fourth entering for particle data that is deposited onto a mesh
is inherited by
:class:`~yt.visualization.plot_window.AxisAlignedSlicePlot`,
:class:`~yt.visualization.plot_window.OffAxisSlicePlot`,
:class:`~yt.visualization.plot_window.ProjectionPlot`, and
:func:`~yt.visualization.plot_window.ProjectionPlot`, and
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`. This
controls the number of resolution elements in the
:class:`~yt.visualization.fixed_resolution.FixedResolutionBuffer`,
Expand Down
4 changes: 3 additions & 1 deletion doc/source/cookbook/simple_off_axis_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@

# Create an OffAxisProjectionPlot of density centered on the object with the L
# vector as its normal and a width of 25 kpc on a side
p = yt.OffAxisProjectionPlot(ds, L, ("gas", "density"), sp.center, (25, "kpc"))
p = yt.ProjectionPlot(
ds, normal=L, fields=("gas", "density"), center=sp.center, width=(25, "kpc")
)
p.save()
2 changes: 1 addition & 1 deletion doc/source/cookbook/simple_plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Making Plots of Multiple Fields Simultaneously

By adding multiple fields to a single
:class:`~yt.visualization.plot_window.SlicePlot` or
:class:`~yt.visualization.plot_window.ProjectionPlot` some of the overhead of
:func:`~yt.visualization.plot_window.ProjectionPlot` some of the overhead of
creating the data object can be reduced, and better performance squeezed out.
This recipe shows how to add multiple fields to a single plot.
See :ref:`slice-plots` and :ref:`projection-plots` for more information.
Expand Down
2 changes: 1 addition & 1 deletion doc/source/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ Most Visible Improvements
Other Changes
^^^^^^^^^^^^^

* :class:`~yt.visualization.plot_window.ProjectionPlot` and
* :func:`~yt.visualization.plot_window.ProjectionPlot` and
:class:`~yt.visualization.plot_window.SlicePlot` supplant the functionality
of PlotCollection.
* Camera path creation from keyframes and splines
Expand Down
2 changes: 1 addition & 1 deletion doc/source/visualizing/callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lines, text, markers, streamlines, velocity vectors, contours, and more.

Callbacks can be applied to plots created with
:class:`~yt.visualization.plot_window.SlicePlot`,
:class:`~yt.visualization.plot_window.ProjectionPlot`,
:func:`~yt.visualization.plot_window.ProjectionPlot`,
:class:`~yt.visualization.plot_window.OffAxisSlicePlot`, or
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot` by calling
one of the ``annotate_`` methods that hang off of the plot object.
Expand Down
14 changes: 7 additions & 7 deletions doc/source/visualizing/plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ generating annotated 2D visualizations of simulation data. You can create a
supplying a dataset, a list of fields to plot, and a plot center to
create a :class:`~yt.visualization.plot_window.AxisAlignedSlicePlot`,
:class:`~yt.visualization.plot_window.OffAxisSlicePlot`,
:class:`~yt.visualization.plot_window.ProjectionPlot`, or
:func:`~yt.visualization.plot_window.ProjectionPlot`, or
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`.

Plot objects use yt data objects to extract the maximum resolution
Expand Down Expand Up @@ -296,7 +296,7 @@ Using a fast adaptive projection, yt is able to quickly project
simulation data along the coordinate axes.

Projection plots are created by instantiating a
:class:`~yt.visualization.plot_window.ProjectionPlot` object. For
:func:`~yt.visualization.plot_window.ProjectionPlot` object. For
example:

.. python-script::
Expand All @@ -322,7 +322,7 @@ the plot to a png image file.
Like :ref:`slice-plots`, annotations and modifications can be applied
after creating the ``ProjectionPlot`` object. Annotations are
described in :ref:`callbacks`. See
:class:`~yt.visualization.plot_window.ProjectionPlot` for the full
:func:`~yt.visualization.plot_window.ProjectionPlot` for the full
class description.

If you want to project through a subset of the full dataset volume,
Expand Down Expand Up @@ -417,7 +417,7 @@ Here, ``W`` is the width of the projection in the x, y, *and* z
directions.

One can also generate annotated off axis projections using
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`. These
:func:`~yt.visualization.plot_window.ProjectionPlot`. These
plots can be created in much the same way as an
``OffAxisSlicePlot``, requiring only an open dataset, a direction
to project along, and a field to project. For example:
Expand All @@ -429,12 +429,12 @@ to project along, and a field to project. For example:
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
L = [1, 1, 0] # vector normal to cutting plane
north_vector = [-1, 1, 0]
prj = yt.OffAxisProjectionPlot(
prj = yt.ProjectionPlot(
ds, L, ("gas", "density"), width=(25, "kpc"), north_vector=north_vector
)
prj.save()

OffAxisProjectionPlots can also be created with a number of
``OffAxisProjectionPlot`` objects can also be created with a number of
keyword arguments, as described in
:class:`~yt.visualization.plot_window.OffAxisProjectionPlot`

Expand Down Expand Up @@ -584,7 +584,7 @@ Note, the change in the field name from ``("deposit", "nbody_mass")`` to

fn = cg.save_as_dataset(fields=[("deposit", "nbody_mass")])
ds_grid = yt.load(fn)
p = yt.OffAxisProjectionPlot(ds_grid, [1, 1, 1], ("grid", "nbody_mass"))
p = yt.ProjectionPlot(ds_grid, [1, 1, 1], ("grid", "nbody_mass"))
p.save()

Plot Customization: Recentering, Resizing, Colormaps, and More
Expand Down
2 changes: 1 addition & 1 deletion doc/source/yt4differences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ centre of the pixel and using the standard SPH smoothing formula. The heavy
lifting in these functions is undertaken by cython functions.

It is now possible to generate slice plots, projection plots, covering grids and
arbitrary grids of smoothed quanitities using these operations. The following
arbitrary grids of smoothed quantities using these operations. The following
code demonstrates how this could be achieved. The following would use the scatter
method:

Expand Down
2 changes: 2 additions & 0 deletions yt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@
apply_colormap,
make_colormap,
plot_2d,
projection_plot,
scale_image,
show_colormaps,
slice_plot,
write_bitmap,
write_image,
write_projection,
Expand Down
8 changes: 2 additions & 6 deletions yt/fields/tests/test_field_access.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from yt.data_objects.profiles import create_profile
from yt.testing import assert_equal, fake_random_ds
from yt.visualization.plot_window import (
OffAxisProjectionPlot,
ProjectionPlot,
SlicePlot,
)
from yt.visualization.plot_window import ProjectionPlot, SlicePlot
from yt.visualization.profile_plotter import PhasePlot, ProfilePlot


Expand All @@ -29,7 +25,7 @@ def test_field_access():
s = SlicePlot(ds, 2, field)
oas = SlicePlot(ds, [1, 1, 1], field)
p = ProjectionPlot(ds, 2, field)
oap = OffAxisProjectionPlot(ds, [1, 1, 1], field)
oap = ProjectionPlot(ds, [1, 1, 1], field)

for plot_object in [s, oas, p, oap, prof, phase]:
plot_object._setup_plots()
Expand Down
2 changes: 2 additions & 0 deletions yt/visualization/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
ProjectionPlot,
SlicePlot,
plot_2d,
projection_plot,
slice_plot,
)
from .profile_plotter import PhasePlot, ProfilePlot
from .streamlines import Streamlines
Loading