# Continuous color scale with distinct colors for under/oversaturated pixels

**URL:** <https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480>\
**Category:** 📊 Plotly Python\
**Created:** [March 11, 2023, 11:30pm UTC](https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480 "2023-03-11T23:30:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Madrigallo](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@Madrigallo](https://community.plotly.com/u/Madrigallo)\
**Post date:** [March 11, 2023, 11:30pm UTC](https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480/1 "2023-03-11T23:30:27Z")

</div>

I would like to visualise under/oversatured pixels with continuous color scale (e.g. pixels with value 0 to be blue, pixels with value 255 to be red, the rest in gray). Is it possible? There are LUTs for this in ImageJ but I could not find the way for plotly in python. Thanks!

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 11, 2023, 11:33pm UTC](https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480/2 "2023-03-11T23:33:17Z")

</div>

HI @Madrigallo welcome to the forums.

Do you want the gray to be grayscale ranging from 1 to 254 or just one color?

---

<div class="post-metadata">

**Author:** ![Madrigallo](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@Madrigallo](https://community.plotly.com/u/Madrigallo)\
**Post date:** [March 11, 2023, 11:35pm UTC](https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480/3 "2023-03-11T23:35:15Z")

</div>

Grayscale, not a single color.

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 11, 2023, 11:41pm UTC](https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480/4 "2023-03-11T23:41:51Z")

</div>

This should get you there, you are searching for a custom colorbar

> [@Discontinous colors while drawing networkx graphs](https://community.plotly.com/t/discontinous-colors-while-drawing-networkx-graphs/71584/2):
>
> Hi @munal , welcome to the forums EDIT: You are searching for a discrete colorbar. Helpful topics: Applying these two to the example from the docs you stated: import plotly.graph\_objects as go import networkx as nx import numpy G = nx.random\_geometric\_graph(200, 0.125) edge\_x = [] edge\_y = [] for edge in G.edges(): x0, y0 = G.nodes[edge[0]]['pos'] x1, y1 = G.nodes[edge[1]]['pos'] edge\_x.append(x0) edge\_x.append(x1) edge\_x.append(None) edge\_y.append(y0) edge\_y…

---

<div class="post-metadata">

**Author:** ![Madrigallo](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@Madrigallo](https://community.plotly.com/u/Madrigallo)\
**Post date:** [March 12, 2023, 12:04am UTC](https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480/5 "2023-03-12T00:04:30Z")

</div>

Thank you, but does that mean I need to specify the gray hue for each value explicitly? I was hoping there was a way that I start with gray scale and selectively modify the color for certain values. How would explicit list of grey hues work for different bit depths in images?

---

<div class="post-metadata">

**Author:** ![Madrigallo](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@Madrigallo](https://community.plotly.com/u/Madrigallo)\
**Post date:** [March 12, 2023, 1:47pm UTC](https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480/6 "2023-03-12T13:47:25Z")

</div>

The solution was to design custom continuous color scale with specified ratios for individual colors. The resulting code which does what I want looks like this:

```auto
custom_colors2 = [[0, "#ff0000"], [0.000001, "#000000"], [0.999999, "#ffffff"], [1, "#0000ff"]]
px.imshow(image, color_continuous_scale=custom_colors2)

```

Setting the ratio for second colour (black here) low enough practically makes the first colour (red) applied to only one pixel value, e. i. zero. So in this way one can combine qualitative and continuous scales, though in a limited way.

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 12, 2023, 2:55pm UTC](https://community.plotly.com/t/continuous-color-scale-with-distinct-colors-for-under-oversaturated-pixels/73480/7 "2023-03-12T14:55:32Z")

</div>

Perfect, glad you figured it out.
