# Discrete heatmap in Plots.jl

**URL:** https://discourse.julialang.org/t/discrete-heatmap-in-plots-jl/35708
**Category:** Visualization
**Created:** [March 8, 2020, 5:55am UTC](https://discourse.julialang.org/t/discrete-heatmap-in-plots-jl/35708 "2020-03-08T05:55:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![c1991](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c1991/32/11851_2.png) [@c1991](https://discourse.julialang.org/u/c1991)
#### Post date: [March 8, 2020, 5:55am UTC](https://discourse.julialang.org/t/discrete-heatmap-in-plots-jl/35708/1 "2020-03-08T05:55:06Z")

</div>

The following code gives me exactly what I need except that I do not want a continuous colorbar. How do I get a discrete color bar (i.e. 1 = “red”, 2 = “blue”, and 3 = “green”, etc.)?

> timePeriods = 12  
> nodes = 15  
> ys = [string(“N”,i) for i in 1:nodes]  
> xs = [string("T ",i) for i in 1:timePeriods]  
> r = rand([1,2,3],nodes,timePeriods)  
> heatmap(xs, ys, r,yflip=true,c=ColorGradient([:red,:blue,:green]))

 ![cont_colorbar](https://global.discourse-cdn.com/julialang/original/3X/4/3/43bce42e39ce86a7083eb1ca09b7b8a96338fe0b.png)

If I use the following code, then I get an error “MethodError: no method matching \_as\_gradient(::Array{RGB{Float64},1})”. This was the code used in the following GitHub issue: [https://github.com/JuliaPlots/Plots.jl/issues/204](https://github.com/JuliaPlots/Plots.jl/issues/204).

> heatmap(xs, ys, r,yflip=true,c=[:red,:blue,:green])

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [March 8, 2020, 6:12am UTC](https://discourse.julialang.org/t/discrete-heatmap-in-plots-jl/35708/2 "2020-03-08T06:12:34Z")

</div>

This page has an example of a discrete colorbar  
[http://docs.juliaplots.org/latest/generated/gr/#gr-ref22-1](http://docs.juliaplots.org/latest/generated/gr/#gr-ref22-1)  
having a look inside `contour` leads [here](https://github.com/JuliaPlots/Plots.jl/blob/7c3938f793b9fa377ec95fe797c77d92813b0f0f/src/backends/gr.jl#L540)  
but from there I can’t really make sense out of it
