When using plotting packages in julia, colors can be passed using a symbol of their name e.g. :red
.
After searching in Makie
’s source code, I could not find where the conversion from Symbol
to colorant was done.
At the moment, it feels like the most direct way to do that is Colors.color_names[String(color_symbol)]
, is it ? It feels quite awkward to do it this way, I would have expected that a Color(color_symbol::Symbol)
existed.
I realize this question was asked 2 years ago, but I came across it and wanted to share the answer if anyone else finds it:
using Colors
mycolor = parse(Colorant,:red)
2 Likes
Ha, thanks for reminding me of this question, I completely forgot about it !
I currently have the actual answer I was looking for under the form of Makie.to_color
. It is however absent from the currently documented API, quite surprisingly, since it is mentioned in the docstring of to_colormap
1 Like
I recommend Colorfy.jl as a more general solution that converts any vector of values into Colors.jl colors. It supports missing values as well.
We had to write this package to support one of our Makie.jl recipes.
1 Like