PlotlyJS Heatmap change colors to grayscale

I want to transform my thermal heatmap to grayscale. I tried different options and arguments, though it keeps returning the standard color format. I’m using the packages below with versions and ran the attached code below to test it on random.

using PlotlyJS, Plots, Distributions, Statistics, ColorSchemes
test_x=vec(collect(1:2:30))
test_y=vec(collect(1:10))
rand_test = Matrix(rand(10, 15))
PlotlyJS.plot(PlotlyJS.heatmap(x=test_x, y=test_y, z=rand_test, seriescolor=cgrad(:grayC)))

# Though just the cgrad for :grayC or :greys shows the right seriescolor
cgrad(:grayC)
cgrad(:greys)

This gives the following heatmap:

Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core™ i7-7700HQ CPU @ 2.80GHz

Package versions
[f0f68f2c] PlotlyJS v0.18.10
[91a5bcdd] Plots v1.36.0
[31c24e10] Distributions v0.25.77
[10745b16] Statistics
[35d6a980] ColorSchemes v3.19.0

Hi,

Firstly, PlotlyJS and Plots are two alternative plotting packages. You could use one or the other, not the two together. Or you may choose to use Plots, and choose the plotlyjs() backend.

Your code works without problem if you choose a built-in color scale from Plotly here. Your code

using PlotlyJS
test_x=vec(collect(1:2:30))
test_y=vec(collect(1:10))
rand_test = Matrix(rand(10, 15))
plot(heatmap(x=test_x, y=test_y, z=rand_test, colorscale = "Greys"))

and the heatmap I think you are looking for:

2 Likes

Yes, I know. I used both as I was using the Plots package for my scatters and bar plots, whereas I used PlotlyJS for the heatmap(). So I will delete one and use the backend.

Thank you, that is probably the reason it didn’t work properly. Though, it should also possible to chose different color scales (From the ColorSchemes package) .

Does this do what your want?

import PlotlyJS
const CS = PlotlyJS.PlotlyBase.ColorSchemes

test_x=vec(collect(1:2:30))
test_y=vec(collect(1:10))
rand_test = Matrix(rand(10, 15))

p = PlotlyJS.heatmap(x=test_x, y=test_y, z=rand_test, colorscale = CS.grayC)
PlotlyJS.plot(p)

q = PlotlyJS.heatmap(x=test_x, y=test_y, z=rand_test, colorscale = CS.grays)
PlotlyJS.plot(q)
1 Like

Yes @jd-foster, thank you very much for showing this!

1 Like