# Creating a color map legend from a lookup table

**URL:** <https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461>\
**Category:** Visualization\
**Created:** [June 26, 2017, 6:19am UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461 "2017-06-26T06:19:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 26, 2017, 6:19am UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461/1 "2017-06-26T06:19:20Z")

</div>

I would like to create a color map legend that shows the value associated with each color displayed in another drawing. Let’s say I have the scalar to color mapping, is there an off-the-shelf function in Julia to draw something like that perhaps in GLVisualize?

![](https://global.discourse-cdn.com/julialang/original/3X/e/d/ed0269beed449263794f5068d41988b6449dfdce.png)

---

<div class="post-metadata">

**Author:** ![anon61610682](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@anon61610682](https://discourse.julialang.org/u/anon61610682)\
**Post date:** [June 27, 2017, 8:43am UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461/2 "2017-06-27T08:43:47Z")

</div>

Will this code excerpt, which is slightly modified from one of the [examples](https://juliaplots.github.io/examples/pyplot/) provided, help? For more info, please check the [attributes](https://juliaplots.github.io/attributes/) section:

```julia
using Plots
pyplot()

xs = [string("x", i) for i = 1:10]
ys = [string("y", i) for i = 1:4]
z = float((1:4) * (1:10)')
heatmap(xs, ys, z, aspect_ratio = 1, colorbar_title = "My Title")

```

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 27, 2017, 10:24pm UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461/3 "2017-06-27T22:24:34Z")

</div>

Can’t verify it because of the following error.

```julia
julia> savefig(fig,"testfig.png")
ERROR: KeyError: key "set_facecolor" not found
 in getindex(::PyCall.PyObject, ::String) at C:\Users\mohd\.julia\v0.5\PyCall\sr
c\PyCall.jl:264
 in getindex(::PyCall.PyObject, ::Symbol) at C:\Users\mohd\.julia\v0.5\PyCall\sr
c\PyCall.jl:269
 in _before_layout_calcs(::Plots.Plot{Plots.PyPlotBackend}) at C:\Users\mohd\.ju
lia\v0.5\Plots\src\backends\pyplot.jl:1077
 in prepare_output(::Plots.Plot{Plots.PyPlotBackend}) at C:\Users\mohd\.julia\v0
.5\Plots\src\plot.jl:247
 in show(::IOStream, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.PyPlotBacke
nd}) at C:\Users\mohd\.julia\v0.5\Plots\src\output.jl:196
 in png(::Plots.Plot{Plots.PyPlotBackend}, ::String) at C:\Users\mohd\.julia\v0.
5\Plots\src\output.jl:8
 in savefig(::Plots.Plot{Plots.PyPlotBackend}, ::String) at C:\Users\mohd\.julia
\v0.5\Plots\src\output.jl:116

```

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [June 28, 2017, 1:59am UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461/4 "2017-06-28T01:59:46Z")

</div>

> [@mohamed82008](#):
>
> ERROR: KeyError: key “set\_facecolor” not found  
> …  
> in \_before\_layout\_calcs(::Plots.Plot{Plots.PyPlotBackend}) at C:\Users\mohd.julia\v0.5\Plots\src\backends\pyplot.jl:1077

This error arises because Plots.jl’s PyPlot backend now requires Matplotlib version 2.0+. The old key name was `:set_axis_bgcolor`. You can change it in your local copy of Plots (at the file/line listed above) if you can’t update Matplotlib easily. (This was the only thing I needed to change in a similar situation.)

---

<div class="post-metadata">

**Author:** ![anon61610682](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@anon61610682](https://discourse.julialang.org/u/anon61610682)\
**Post date:** [June 28, 2017, 7:33am UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461/5 "2017-06-28T07:33:41Z")

</div>

> [@mohamed82008](#):
>
> Can’t verify it because of the following error.

You can change the plotting backend to something else, _e.g._, `pyplot()` to `gr()`.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 28, 2017, 5:31pm UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461/6 "2017-06-28T17:31:26Z")

</div>

Tried it with gr and it worked. Seems promising, but I think I will stick with VTK for now. Thanks. That’s a glimpse of what I am working on btw.

 ![](https://global.discourse-cdn.com/julialang/original/3X/e/8/e8f051fa9d285653d534745ad931ecb08abb4f48.png)

---

<div class="post-metadata">

**Author:** ![anon61610682](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@anon61610682](https://discourse.julialang.org/u/anon61610682)\
**Post date:** [June 28, 2017, 8:03pm UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461/7 "2017-06-28T20:03:42Z")

</div>

I am not sure if you have privileges, but if you do have, please consider marking the corresponding response as the answer to the question for easy access later on.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 28, 2017, 8:18pm UTC](https://discourse.julialang.org/t/creating-a-color-map-legend-from-a-lookup-table/4461/8 "2017-06-28T20:18:29Z")

</div>

Seems like I can’t, perhaps the privileges rules changed cuz I remember I used to be able to.

ETA: Bookmarked it.
