While LinePlot doesn't seem to do what you're trying to, since it doesn't work for SPH datasets, you can try this alternative way to determine properties along a line through your simulation's volume.  (Note to other devs, this might be a good way to fix the problem with LinePlot not working on SPH datasets, since the ray object does work with SPH datasets).  Replace your final line's call to `LinePlot` with the lines below for creating a ray and then manually plotting the fields along that ray ('t' field is just a parametric length along the ray).  Here are some notes on ray objects:

import yt
import matplotlib.pyplot as plt
import numpy as np
#Load the dataset and create the ray
ds = yt.load(YOUR_DATASET)
ray = ds.ray((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)) #start and end coords of line through data

#Order the density field along its trajectory using "t" field (parametric length)
ray_sort = np.argsort(ray["t"])
density = ray["gas", "density"][ray_sort]
t = ray["t"][ray_sort]

#Plot density vs "t"--the length along the field
plt.plot(t, density)

On Mon, Aug 8, 2022 at 10:58 AM Matthew Turk <> wrote:
Hi Christian,

If I am following Slack right, I think this got resolved -- or is there more we should do to help out?

On Tue, Jul 26, 2022 at 7:55 AM Christian van der Merwe via yt-users <> wrote:
Hi all,

I am very new to YT and I have been trying to create a line plot for my GADGET-4 simulation output, but I keep running into a problem.

I try to do a similar plot as that found here: I want to be able to 'draw' an arbitrary line and see how a quantity such as density changes along that line. My script and an example snapshot is linked below with the error I am getting following after.

The code:
The snapshot and code:
YT version: 4.0.4

I keep getting this traceback error:

" Traceback (most recent call last):

  File ~/PATH/ in <module>
    plot = yt.LinePlot(ds, "Density", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), 1000)

  File ~/.local/lib/python3.9/site-packages/yt/visualization/ in __init__

  File ~/.local/lib/python3.9/site-packages/yt/visualization/ in _setup_plots
    x, y = self.ds.coordinates.pixelize_line(

  File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/ in pixelize_line
    arc_length, plot_values = _sample_ray(ray, npoints, field)

  File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/ in _sample_ray
    ray_coordinates = uvstack([ray[("index", d)] for d in "xyz"]).T

  File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/ in <listcomp>
    ray_coordinates = uvstack([ray[("index", d)] for d in "xyz"]).T

  File ~/.local/lib/python3.9/site-packages/yt/data_objects/ in __getitem__

  File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/ in get_data

  File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/ in _generate_fields
    fd = self._generate_field(field)

  File ~/.local/lib/python3.9/site-packages/yt/data_objects/ in _generate_field
    tr = self._generate_fluid_field(field)

  File ~/.local/lib/python3.9/site-packages/yt/data_objects/ in _generate_fluid_field
    rv = finfo(gen_obj)

  File ~/.local/lib/python3.9/site-packages/yt/fields/ in __call__
    dd = self._function(self, data)

  File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/ in _coords
    rv = data.ds.arr(data.fcoords[..., axi].copy(), units)

  File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/ in fcoords
    return self._current_chunk.fcoords

  File ~/.local/lib/python3.9/site-packages/yt/geometry/ in cached_func
    tr = self._accumulate_values(n[1:])

  File ~/.local/lib/python3.9/site-packages/yt/geometry/ in _accumulate_values

  File ~/.local/lib/python3.9/site-packages/yt/data_objects/index_subobjects/ in _func_non_indexed
    raise YTNonIndexedDataContainer(self)

YTNonIndexedDataContainer: The data container (<class 'yt.data_objects.index_subobjects.particle_container.ParticleContainer'>) is an unindexed type.  Operations such as ires, icoords, fcoords and fwidth will not work on it."

Help with this would be highly appreciated.

Kind regards,
yt-users mailing list --
To unsubscribe send an email to
Member address:
yt-users mailing list --
To unsubscribe send an email to
Member address:

Cameron Hummels
Computational Astrophysicist
California Institute of Technology