# Julia plots: How to fill graph background with different colors

**URL:** https://discourse.julialang.org/t/julia-plots-how-to-fill-graph-background-with-different-colors/17040
**Category:** General Usage
**Tags:** package, plotting
**Created:** [November 1, 2018, 7:41am UTC](https://discourse.julialang.org/t/julia-plots-how-to-fill-graph-background-with-different-colors/17040 "2018-11-01T07:41:51Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [July 11, 2021, 9:11pm UTC](https://discourse.julialang.org/t/julia-plots-how-to-fill-graph-background-with-different-colors/17040/8 "2021-07-11T21:11:53Z")

</div>

In reviewing this post, it appears that the following code more directly answers the OP’s question:

 ![plot_gr_threshold_filled_areas](https://global.discourse-cdn.com/julialang/original/3X/7/7/77629d643773c07c0626be6aedef66b166605161.png)

_ **NB:** Congratulazioni Italia!_

```julia
using Plots; gr()
theme(:dark)

x = LinRange(0,π,2021); y = 2*cos.(x)
ymin, ymax = extrema(y)
c = [-1.; 1.] # BAD < -1 ; -1 < OK < 1; GOOD > 1
cs = @. (c - ymin)/(ymax - ymin) # map input data ranges to color scale 0-1 range:
my_cgrad2 = cgrad([:red,:white,:green], cs, categorical=true)

scatter([-1 -1 -1],[0 0 0], mc=[:red :white :green],label=["BAD < -1" "-1 < OK < 1" "GOOD > 1"],marker=:rect, ratio=1)
plot!(x,y, fill=true,fill_z=y,fc=my_cgrad2, colorbar=false,clims=(ymin,ymax),lc=:black,
     xlabel="x", ylabel="y", widen=false,label=false, xlims=extrema(x),ylims=(-2.1,2.1))
plot!(xticks=([0, pi/3, 2pi/3, pi], ["0","π/3","2π/3", "π"]), dpi=300)

```

---

_[View the full topic](https://discourse.julialang.org/t/julia-plots-how-to-fill-graph-background-with-different-colors/17040)._
