# Specify Datashader colors outside of color limits

**URL:** <https://discourse.holoviz.org/t/specify-datashader-colors-outside-of-color-limits/8561>\
**Category:** Datashader\
**Tags:** bokeh, holoviews\
**Created:** [February 6, 2025, 11:27am UTC](https://discourse.holoviz.org/t/specify-datashader-colors-outside-of-color-limits/8561 "2025-02-06T11:27:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![droumis](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/droumis/32/1674_2.png) [@droumis](https://discourse.holoviz.org/u/droumis)\
**Post date:** [February 6, 2025, 2:42pm UTC](https://discourse.holoviz.org/t/specify-datashader-colors-outside-of-color-limits/8561/4 "2025-02-06T14:42:14Z")

</div>

Maybe @jbednar or @philippjfr can chime in if there’s a less cumbersome approach, but you could avoid HoloViews and Bokeh altogether by filtering the highs and lows out and stacking the resulting images.

```python
import numpy as np
import pandas as pd
import datashader as ds
import datashader.transfer_functions as tf
import colorcet as cc

N = 500
low_thresh = 3
high_thresh = 7

xs = np.linspace(0, 10, N)
ys = np.linspace(0, 10, N)
X, Y = np.meshgrid(xs, ys)
val = X.ravel()

df = pd.DataFrame({
    'x': X.ravel(),
    'y': Y.ravel(),
    'val': val,
})

canvas = ds.Canvas(plot_width=400, plot_height=200, x_range=(0, 10), y_range=(0, 10))
agg = canvas.points(df, 'x', 'y', agg=ds.mean('val'))

agg_in = agg.where((agg >= low_thresh) & (agg <= high_thresh))
img_in = tf.shade(agg_in, cmap=cc.bgy, span=(low_thresh, high_thresh), how='linear')

agg_low = agg.where(agg < low_thresh)
img_low = tf.shade(agg_low, cmap=["red"])

agg_high = agg.where(agg > high_thresh)
img_high = tf.shade(agg_high, cmap=["orange"])

final_img = tf.stack(img_low, img_in, img_high)

final_img

```

![image](https://discourse.holoviz.org/uploads/default/original/2X/d/d5f2b03af0e45e680a60b344c3bb6a46e8bc9c50.png)

---

_[View the full topic](https://discourse.holoviz.org/t/specify-datashader-colors-outside-of-color-limits/8561)._
