Obtaining Colors with Values from 0 to 1 in the Julia Color Scheme
Overview
To obtain colors in the range from 0 to 1 in Julia’s color scheme, use the get
function1. Although this function originally exists in Base
, it has been overloaded through using ColorSchemes
.
Code
The color scheme used in the example is colorschemes[:plasma]
.
colorschemes[:plasma]
By inputting a value between 0 and 1 as the second argument to the get
function, you can obtain the exact color at that position in the continuous color scheme.
[get(colorschemes[:plasma], x) for x in [.3, .7, .1, .5, .9]]
Meanwhile, since the get
function originally accepts an array of real numbers and returns an array of colors, it can be used as follows without necessarily broadcasting. In a way, the interface that allows for obtaining a single color even with a scalar input could be considered an exceptional feature.
get(colorschemes[:plasma], .2:.2:1)
Full Code
using ColorSchemes
colorschemes[:plasma]
[get(colorschemes[:plasma], x) for x in [.3, .7, .1, .5, .9]]
get(colorschemes[:plasma], .2:.2:1)
Environment
- OS: Windows
- julia: v1.10.0