Hi Logan,
Something like this *may* work:
import yt
ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
plot = yt.SlicePlot(ds, 2, 'density')
plot.annotate_grids()
plot._setup_plots()
fig = plot.plots['gas','density'].figure
with yt.funcs.matplotlib_style_context():
fig.savefig('my_plot.pdf', transparent=True)
I say *may* because when I try locally I can't even make a regular matplotlib plot that doesn't use yt at all save as a transparent PDF. It works with png though. I have no idea why transparent PDFs aren't working for me, perhaps it's related to
https://github.com/matplotlib/matplotlib/issues/3841.
Note that when you do stuff like this you need to run _setup_plots() after you've done all of the yt-related plot customizations. After _setup_plots() runs the plot should be fully set up. The usage of matplotlib_style_context() is only there to get matplotlib to use fonts matching the rest of the plot and not dejavu sans. Unfortunately matplotlib doesn't have an API to set that option on the plot itself so we need to use matplotlib's style context manager to override the defaults.
We could probably make generating a transparent plot easier, for example by adding a new method like plot.set_transparent(False) that then sets the transparency on the appropriate matplotlib patch objects manually. Unfortunately we need to use canvas.print_figure() to save the images because we're not using pyplot under the hood so we need to do things at a bit more of a lower level in matplotlib than you might be used to.