# Plot colour based on conditional

**URL:** https://discourse.julialang.org/t/plot-colour-based-on-conditional/88005
**Category:** New to Julia
**Tags:** plotting, plot
**Created:** [September 29, 2022, 7:03pm UTC](https://discourse.julialang.org/t/plot-colour-based-on-conditional/88005 "2022-09-29T19:03:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Max\_Beez](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Beez](https://discourse.julialang.org/u/Max_Beez)
#### Post date: [September 29, 2022, 7:03pm UTC](https://discourse.julialang.org/t/plot-colour-based-on-conditional/88005/1 "2022-09-29T19:03:19Z")

</div>

Is it possible to set a plot colour based on a conditional statement?

In the plot method I use, for example, color = [:gray :gray :gray] to give me gray-coloured plot for three plots which appear in a side-by-side configuration.

So I would like to be able to have this plot colour change based on an if-else statement but I can’t seem to get that to work in Julia.

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [September 29, 2022, 8:35pm UTC](https://discourse.julialang.org/t/plot-colour-based-on-conditional/88005/2 "2022-09-29T20:35:11Z")

</div>

```julia
colorcond(x) = x<0 ? :red : :green
x = randn(50)
plot(x; color=colorcond.(x))

```

---

<div class="post-metadata">

### Author: ![Max\_Beez](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Beez](https://discourse.julialang.org/u/Max_Beez)
#### Post date: [September 29, 2022, 9:35pm UTC](https://discourse.julialang.org/t/plot-colour-based-on-conditional/88005/3 "2022-09-29T21:35:32Z")

</div>

Doesn’t quite work as intended for my purpose but this nonetheless does provide a bit of an answer. Thank you.
