# Drop values near zero in contour fill plot for Makie

**URL:** <https://discourse.julialang.org/t/drop-values-near-zero-in-contour-fill-plot-for-makie/95050>\
**Category:** Visualization\
**Tags:** question, plotting, makie\
**Created:** [February 22, 2023, 11:47pm UTC](https://discourse.julialang.org/t/drop-values-near-zero-in-contour-fill-plot-for-makie/95050 "2023-02-22T23:47:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![garrek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrek/32/27937_2.png) [@garrek](https://discourse.julialang.org/u/garrek)\
**Post date:** [February 22, 2023, 11:47pm UTC](https://discourse.julialang.org/t/drop-values-near-zero-in-contour-fill-plot-for-makie/95050/1 "2023-02-22T23:47:55Z")

</div>

I’m trying to plot some data using a contour plot in Makie. My data has both negative and positive peaks. Near zero, there is a lot of noise. I want to highlight just the main peaks and valleys and I’d like anything near zero to be white. Makie’s `contourf` function has a `:relative` mode ([see here](https://docs.makie.org/stable/examples/plotting_functions/contourf/#relative_mode)) where you can drop either the high or low ranges, say the bottom 10%. I would like to drop the middle 10% or so, or somehow set the middle to be white so the peaks are easily identifiable.

I’ve tried creating two contour plots and overlapping them: one with the highest 95% (positive values) and one with the lowest 95% (the negative values). This actually gets very close to what I want, visually, but then each plot has its own `Colorbar` (blue gradient for positive and red for negative), which is not desirable.

Another option would be to apply a filter to the dataset and set very small values to zero, but I don’t really want to be manipulating the data.

Is there a way I haven’t thought of? Maybe there’s a way to set the levels that I’m not thinking of?

Here’s an example of roughly what I would like to achieve (this is not my data, but is similar, and I’m not sure how it was generated):

 ![Screenshot 2023-02-22 at 15.46.00](https://global.discourse-cdn.com/julialang/original/3X/7/c/7c9207c01316e385ec1a2fd2e2bfee79cc33c938.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 23, 2023, 10:30am UTC](https://discourse.julialang.org/t/drop-values-near-zero-in-contour-fill-plot-for-makie/95050/2 "2023-02-23T10:30:52Z")

</div>

How about this:

```julia
data = [sin(x) * cos(y) for x in 0:0.1:4, y in 0:0.1:4] .+ 0.05 .* randn.()
zeroband_threshold = 0.2
threshold = maximum(abs, data)
nbands = 15
upperrange = range(zeroband_threshold, threshold, (nbands-1)÷2)
levels = [reverse(.-upperrange); upperrange]
f, ax, c = contourf(data, levels = levels, colormap = :RdBu)
contour!(ax, data, levels = levels, color = :black)
tightlimits!(ax)
Colorbar(f[1, 2], c)
f

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/0/108089af62308ce70a058f399cd9ea4b28939128.jpeg)

---

<div class="post-metadata">

**Author:** ![garrek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrek/32/27937_2.png) [@garrek](https://discourse.julialang.org/u/garrek)\
**Post date:** [February 23, 2023, 5:16pm UTC](https://discourse.julialang.org/t/drop-values-near-zero-in-contour-fill-plot-for-makie/95050/3 "2023-02-23T17:16:55Z")

</div>

That looks really nice. Thank you for also including the black contour outlines. I didn’t think of that but it looks good.
