Making Custom Colormap with Makie


I’m wondering what is the best way to implement my own custom colormap for use in Makie. I am using CairoMakie to generate plots and I want to be able to specify a colormap and then generate smaller maps from those for the purposes of coloring line plots. For example, there is a colormap called :Dark2_8. I can generate a subset of colors for plotting from that by doing resample_cmap(:Dark2_8, 6) (if I have 6 lines in my plot for example).

Currently I have my custom map implemented like this.

mymap = [ ... ]  # Vector of 20 colors defined as a vector of RGBf()

Then I create the smaller lists of colors for line plots by doing

mymap4 = resample_cmap(mymap, 4)

This appears to work.

But I’m wondering if there is the best way. For example, how could I implement it so that it behaves like :Dark2_8 so that I could call mymap4 = resample_cmap(:mymap, 4).

I tried the following (based on the source here).


But I get the following error when I try to do resample_cmap(:mymap, 4)

ERROR: There is no color gradient named mymap.
See `Makie.available_gradients()` for the list of available gradients,
or look at