# Colour gradient using a given function when plotting

**URL:** <https://community.wolfram.com/t/colour-gradient-using-a-given-function-when-plotting/20888>\
**Category:** Questions\
**Tags:** graphics-and-visualization\
**Created:** [October 16, 2022, 2:04pm UTC](https://community.wolfram.com/t/colour-gradient-using-a-given-function-when-plotting/20888 "2022-10-16T14:04:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tedbar](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@tedbar](https://community.wolfram.com/u/tedbar)\
**Post date:** [October 16, 2022, 2:04pm UTC](https://community.wolfram.com/t/colour-gradient-using-a-given-function-when-plotting/20888/1 "2022-10-16T14:04:41Z")

</div>

Given a function, in this case reflecting risk as a function of depth, with 0 \<= f(y) \<= 1:

```
r [y_] := 1 - (y/100)^2

```

I wish to scale a colour gradient, along the lines of

```
risk = RegionPlot[r[y] <= 1, {x, -200, 200}, {y, 0, -100}, 
  ColorFunction -> "Rainbow"]

```

using the risk function (given above) i.e. red = high risk and blue = low risk with the rate of change of colour controlled by the function. Then add a legend in the form of a colour bar and associated values. This will form the background for various plots using different risk profiles.

The final plots will look something like:

 ![whale_depth.png](https://global.discourse-cdn.com/wolfram/original/3X/4/1/41a168a342eec53f6818cdd58c530ee5a9e97ceb.png)

---

<div class="post-metadata">

**Author:** ![eric3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/eric3/32/12760_2.png) [@eric3](https://community.wolfram.com/u/eric3)\
**Post date:** [October 16, 2022, 5:10pm UTC](https://community.wolfram.com/t/colour-gradient-using-a-given-function-when-plotting/20888/2 "2022-10-16T17:10:43Z")

</div>

◔

---

<div class="post-metadata">

**Author:** ![tedbar](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@tedbar](https://community.wolfram.com/u/tedbar)\
**Post date:** [October 17, 2022, 2:06pm UTC](https://community.wolfram.com/t/colour-gradient-using-a-given-function-when-plotting/20888/3 "2022-10-17T14:06:50Z")

</div>

Thank you, it has certainly got me started. The final plot is pretty much what I am looking for (without the reversal).
