Custom Colorbar TickmarksΒΆ

Notebook
In [1]:
import yt
In [2]:
ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
slc = yt.SlicePlot(ds, 'x', 'density')
slc
Out[2]:

PlotWindow plots are containers for plots, keyed to field names. Below, we get a copy of the plot for the Density field.

In [3]:
plot = slc.plots['density']

The plot has a few attributes that point to underlying matplotlib plot primites. For example, the colorbar object corresponds to the cb attribute of the plot.

In [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.

In [5]:
slc._setup_plots()

To set custom tickmarks, simply call the matplotlib set_ticks and set_ticklabels functions.

In [6]:
colorbar.set_ticks([1e-28])
colorbar.set_ticklabels(['$10^{-28}$'])
slc
Out[6]:

(custom_colorbar_tickmarks.ipynb; custom_colorbar_tickmarks_evaluated.ipynb; custom_colorbar_tickmarks.py)