# Is there a way to obtain a colorant from color name provided as a Symbol?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-obtain-a-colorant-from-color-name-provided-as-a-symbol/88663
**Category:** General Usage
**Tags:** question, colors
**Created:** [October 13, 2022, 12:53pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-obtain-a-colorant-from-color-name-provided-as-a-symbol/88663 "2022-10-13T12:53:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)
#### Post date: [October 13, 2022, 12:53pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-obtain-a-colorant-from-color-name-provided-as-a-symbol/88663/1 "2022-10-13T12:53:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![RobertGregg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertgregg/32/22105_2.png) [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)
#### Post date: [August 9, 2024, 9:09pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-obtain-a-colorant-from-color-name-provided-as-a-symbol/88663/2 "2024-08-09T21:09:10Z")

</div>

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:

```julia
using Colors
mycolor = parse(Colorant,:red)

```

---

<div class="post-metadata">

### Author: ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)
#### Post date: [August 9, 2024, 11:09pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-obtain-a-colorant-from-color-name-provided-as-a-symbol/88663/3 "2024-08-09T23:09:27Z")

</div>

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`](https://github.com/MakieOrg/Makie.jl/blob/c83dda467a2492036948a94879fa221b0462f678/src/conversions.jl#L862-L879). It is however absent from the currently documented API, quite surprisingly, since it is mentioned in the docstring of [`to_colormap`](https://docs.makie.org/stable/api#Makie.to_colormap-Tuple%7BAbstractVector%7D)

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [August 10, 2024, 12:30am UTC](https://discourse.julialang.org/t/is-there-a-way-to-obtain-a-colorant-from-color-name-provided-as-a-symbol/88663/4 "2024-08-10T00:30:28Z")

</div>

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.
