How to set a reversed colormap in a heatmap definition

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.

4 Likes