# Change float into color or change array of Floats into colormap

**URL:** <https://discourse.julialang.org/t/change-float-into-color-or-change-array-of-floats-into-colormap/24861>\
**Category:** General Usage\
**Tags:** question, package, plotting, performance, colors\
**Created:** [June 2, 2019, 7:23pm UTC](https://discourse.julialang.org/t/change-float-into-color-or-change-array-of-floats-into-colormap/24861 "2019-06-02T19:23:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wiktorkujawa](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)\
**Post date:** [June 2, 2019, 7:23pm UTC](https://discourse.julialang.org/t/change-float-into-color-or-change-array-of-floats-into-colormap/24861/1 "2019-06-02T19:23:27Z")

</div>

Hi, I want to change array of Floats(Calculated Values of Magnetic Induction) into colormap in cimgui app. I want something like this([matlab colormaps](https://www.mathworks.com/help/matlab/ref/colormap.html)). I wrote simillar question [here](https://discourse.julialang.org/t/generating-plots-heatmap-surf-mesh-using-cimgui-and-cuda-libraries/24597).  
I just thinked how to achieve this in hard way(no package, just clear code and algorithm) and I knew that I should find the highest and lowest value in my table. For the highest and lowest I should assign some two extreme values and with some linear algorithm assign the mid values to the colors. For example in HSVA format I could assign H=170 for lowest value and H=0 for highest value(S, V and A would be constant) and for mid values assign appropriate colors and assign them to new array however i am sure that there are some ready-made solutions(like matlab colormaps). If you know how to achieve that I would be grateful.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [June 3, 2019, 1:05am UTC](https://discourse.julialang.org/t/change-float-into-color-or-change-array-of-floats-into-colormap/24861/2 "2019-06-03T01:05:54Z")

</div>

If you want to create an array with RGB color entries from a scalar-valued array, look at ImageCore’s `scalesigned` and `colorsigned`. Demo, assuming the min value is -0.2 and the max value is 1.0:

```julia
julia> f = colorsigned() ∘ scalesigned(-0.2, 0, 1.0)
#56 (generic function with 1 method)

julia> f(-0.2)
RGB{N0f8}(0.0,1.0,0.0)

julia> f(0)
RGB{N0f8}(1.0,1.0,1.0)

julia> f(1)
RGB{N0f8}(1.0,0.0,1.0)

julia> f.(A) # map the values of array A into colors

```

---

<div class="post-metadata">

**Author:** ![wiktorkujawa](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)\
**Post date:** [June 3, 2019, 3:09pm UTC](https://discourse.julialang.org/t/change-float-into-color-or-change-array-of-floats-into-colormap/24861/3 "2019-06-03T15:09:40Z")

</div>

Thanks, that’s what I looked for. I’ll go through documentation to find other colourways(I assume that `colorsigned() ` takes default colourway that is from white to pink).
