Closed alex-s-gardner closed 2 days ago
Hi! What exactly do those functions (PlotUtils.palette
Makie.resample_cmap
) do?
They simply discretize a color gradient with a requested number of samplings .
I often find myself wanting to create a new color palette of n colors from a gradient. Does that make sense?
For example:
the desired function f
could create :acton10
:
acton10 = f(:acton, 10)
but also any other integer number of samples
This is sort of built in:
using ColorSchemes
acton10 = ColorScheme(
get(ColorSchemes.acton, 0.0:0.1:1.0))
get
allows various kinds of sampling; the ColorScheme
constructor converts the vector of colors to a ColorScheme.
Ah man... I wish I had found get
a long time ago.. didn't think of using ranges. I wonder if it's worth including this example under basic usage
I do think a helper function would still be welcome:
function resample(colorscheme, n)
newscheme = ColorScheme(
get(ColorSchemes[colorscheme], (0:n)/n))
end
I think it would be a good idea to add more information to the docstrings and documentation, particularly if it's not that easy to find at the moment. Perhaps using words like "resample" might help discoverability....
I added some more words to the documentation.
Looks good, thanks. Would you be oppose to adding a resample function? For people that are newer to the language:
get(ColorSchemes.darkrainbow, range(0.0, 1.0, length=20)) |> ColorScheme
can be a bit intimidating to resample a colormap. I think a resample function is simple, robust and intuitive. I'd be happy to make a PR.
It would be nice to have a function within ColorSchemes to convert between a Gradient.
To Gradient a ColorSchemes gradient you need a function from another package: either 'PlotUtils.palette' or 'Makie.resample_cmap'
It seems that such a basic functionality should live within ColorSchemes