Custom Colorbar Tickmarks¶
[1]:
import yt
[2]:
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
slc = yt.SlicePlot(ds, "x", ("gas", "density"))
slc
[2]:
PlotWindow
plots are containers for plots, keyed to field names. Below, we get a copy of the plot for the Density
field.
[3]:
plot = slc.plots[("gas", "density")]
The plot has a few attributes that point to underlying matplotlib
plot primitives. For example, the colorbar
object corresponds to the cb
attribute of the plot.
[4]:
colorbar = plot.cb
Next, we call _setup_plots()
to ensure the plot is properly initialized. Without this, the custom tickmarks we are adding will be ignored.
[5]:
slc._setup_plots()
To set custom tickmarks, simply call the matplotlib
`set_ticks
<https://matplotlib.org/stable/api/colorbar_api.html#matplotlib.colorbar.ColorbarBase.set_ticks>`__ and `set_ticklabels
<https://matplotlib.org/stable/api/colorbar_api.html#matplotlib.colorbar.ColorbarBase.set_ticklabels>`__ functions.
[6]:
colorbar.set_ticks([1e-28])
colorbar.set_ticklabels(["$10^{-28}$"])
slc
[6]: