Dear Nick

You should be able to achieve this using the .frb attribute of any slice plot object (or projection plot actually).

def combine_by_value(a: np.ndarray, b: np.ndarray) -> np.ndarray:

    """Combine two RGB(a) arrays into one.
    Parameters
    ---------------
    a : RGBa array
        The array to take the value from. This works well if a is in gray scales
    b : RGBa array
        The array to take hue and saturation from.

    Returns
    -----------
    c : RGB array
        An array with hue and saturation from b and value from a.
    """ 
    # Note: rgb_to_hsv only accepts RGB arrays, not RGBa ones so we need to strip out the alpha channel
    a_hsv, b_hsv = (plt.matplotlib.colors.rgb_to_hsv(_[..., :3]) for _ in (a, b))

    # We get the saturation from a and the hue/value from b
    c_hsv = b_hsv.copy()

    c_hsv[..., 2] = a_hsv[..., 2]
    return plt.matplotlib.colors.hsv_to_rgb(c_hsv)

p = yt.SlicePlot(ds, …)
dens = p.frb["gas", "density"]  # this will be the 2D array that would have been plotted otherwise
neutral = p.frb["gas", "neutral_fraction"]  # or whatever name your field has

fig, ax = plt.subplots()
norm = plt.matplotlib.colors.LogNorm

# Apply colour maps to our two fields
dens_colors = plt.cm.Grays(norm()(dens))
neutral_colors = plt.cm.Oranges(norm()(neutral))

# Now we mix them
combined_colors = combine_by_luminosity(dens_colors, neutral_colors)
## You could also do something like
# combined_colors = (dens_colors + neutral_colors) / 2
plt.imshow(combined_colors)

On 04/03/2022 01:32, Nick Gnedin wrote:


I wonder if I can plot slices of two fields overlaid, with the top field being partially translucent, so that the bottom field is also visible. Specifically, I would like to show gas density in greyscale, overlaid with the neutral fraction with low opacity and a sequential cmap like "Oranges", then the relation between the gas density and ionized regions will be very visible.

_______________________________________________
yt-users mailing list -- yt-users@python.org
To unsubscribe send an email to yt-users-leave@python.org
https://mail.python.org/mailman3/lists/yt-users.python.org/
Member address: contact@cphyc.me