How to set a reversed colormap in a heatmap definition

For older Plots versions I found out that it was posssible to set the reversed colormap by c=:viridis_r, but now it generates the error
Unknown color: viridis_r:

using Plots
h=0.05
y, x = range(-5,  stop=5+h, step=h), range(-5, stop=10+h, step=h)
X = [xx for yy in y, xx in x]
Y = [yy for yy in y, xx in x]   
z = (sin.(X)) .^10 + cos.(10 .+ Y .* X) + cos.(X) + 0.2*Y + 0.1*X
heatmap(x, y, z, c=:viridis_r)

color palettes are, as far as I know, often found in ColorSchemes. And in the manual I see :viridis, maybe that works for you?

You can simply do

heatmap(x, y, z, c=cgrad(:viridis, rev=true))

or

heatmap(x, y, z, c=reverse(cgrad(:viridis)))

ref. ColorGradient

P.S. More simply,

using Plots
h=0.05
x, y = -5:h:10+h, -5:h:5+h
f(x, y) = sin(x) ^10 + cos(10 + x * y) + cos(x) + 0.2y + 0.1x
heatmap(x, y, f, c=cgrad(:viridis, rev=true))

A lot of dots in one line can often cause bugs.

3 Likes