Creating a color map legend from a lookup table

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?

Will this code excerpt, which is slightly modified from one of the examples provided, help? For more info, please check the attributes section:

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")

Can’t verify it because of the following error.

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

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.)

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

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.

1 Like

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.

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

ETA: Bookmarked it.