# How to set a reversed colormap in a heatmap definition

**URL:** https://discourse.julialang.org/t/how-to-set-a-reversed-colormap-in-a-heatmap-definition/63155
**Category:** Visualization
**Created:** [June 18, 2021, 7:11pm UTC](https://discourse.julialang.org/t/how-to-set-a-reversed-colormap-in-a-heatmap-definition/63155 "2021-06-18T19:11:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [June 18, 2021, 7:11pm UTC](https://discourse.julialang.org/t/how-to-set-a-reversed-colormap-in-a-heatmap-definition/63155/1 "2021-06-18T19:11:12Z")

</div>

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`:

```julia
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)

```

---

<div class="post-metadata">

### Author: ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)
#### Post date: [June 18, 2021, 9:43pm UTC](https://discourse.julialang.org/t/how-to-set-a-reversed-colormap-in-a-heatmap-definition/63155/2 "2021-06-18T21:43:55Z")

</div>

color palettes are, as far as I know, often found in `ColorSchemes`. And in the [manual](https://docs.juliaplots.org/latest/generated/colorschemes/) I see `:viridis`, maybe that works for you?

---

<div class="post-metadata">

### Author: ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)
#### Post date: [June 19, 2021, 3:01am UTC](https://discourse.julialang.org/t/how-to-set-a-reversed-colormap-in-a-heatmap-definition/63155/3 "2021-06-19T03:01:32Z")

</div>

You can simply do

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

```

or

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

```

ref. [ColorGradient](http://docs.juliaplots.org/latest/colorschemes/#ColorGradient)

P.S. More simply,

```julia
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.
