# Makie: open-ended contouring levels for contourf?

This thread discusses how to limit the contouring values. My question is a followup on that: How to paint all values above and below the limits and coordinate with the colorbar?

The first image below is what I need and the second image is what my little Julia program (shown at the very end) produces. Please focus on the colorbar of the first image: the (-Inf, -0.5) range is painted in the lowest extreme color of viridis and the (0.5, Inf) range is painted in the highest extreme color, and the colorbar has little triangles at the ends.

The Makie:Colorbar tutorial shows how to use `lowclip` and `highclip`, so there is a great hope, but I donâ€™t know how to limit the color range of the palette (viridis, in the present case) and reserve the highest and lowest extreme colors for the triangles. (Okay, I could create my own version of viridis removing the extremities and use them for the `lowclip` and `highclip` colors, but that would be super tedious . . .)

In any case, this kind of open-ended contouring is so common (at least in my field) that it would be nice if there be a half-automatic solution.

Iâ€™ve tried `levels = vcat(-Inf, -0.5:0.1:0.5, Inf)`, which I thought would be an obvious solution but which resulted in error.

``````using CairoMakie

func(x,y) = cos(2Ď€*x/100) * sin(2Ď€*y/100)

xs = 0:10:100
ys = 0:10:100
arr = func.(xs, reshape(ys,1,:))

fig = Figure()
ax = Axis(fig[1,1])
tightlimits!(ax)
c = contourf!(ax, xs, ys, arr; levels=-0.5:0.1:0.5)
Colorbar(fig[1,2], c)
save("tmp2.png", fig)
``````

This is called `extendlow` and `extendhigh` for `contourf` contourf Â· Makie. I didnâ€™t call it `highclip` and `lowclip` precisely because you take a chunk out of the colorbar basically, which doesnâ€™t happen for the continuous variants you find in `heatmap` etc.

1 Like

Thank you!!!

First, I shouldâ€™ve looked at the manual of `contourf` before resorting to search. Sorry for not having done my homework properly.

Also, I wonder whether it would make sense

1. to enable encoding `extend???` in contour levels. For example, `levels=vcat(-Inf, -10:1:10)` would imply `levels=-10:1:10, extendlow=:auto` . . . ? Or

2. to introduce a â€ślevels objectâ€ť, something that behaves like `levs = (levels = -10:1:10, extendlow = :auto)` . . . ?

My current solution is to simulate 2 above:

``````function myplot( . . . ; levs = ()) # defaulting to an empty tuple
# . . .
contourf( . . . ; levs...)
# . . .
end

levs = if (somecond) ? (levels=-10:1:10, extendlow = :auto) : (levels = -1:0.1:1)
myplot(. . . ; levs = levs)
``````

This isnâ€™t too bad at all. Itâ€™s more general, too; that is, to bundle any attributes together as you like. I just thought that `extend???` and `levels` combined conceptually form a single object in the userâ€™s mind.

Off topic: Iâ€™m finding that `Makie` doesnâ€™t seem to have a unified â€śundefinedâ€ť value for attributes, which confuses me a lot:

``````function myplot(. . . ; axislabel = nothing)
fig = Figure()
ax = Axis(fig[1,1]; ylabel = axislabel) # <- does this work?
``````

For `String` attributes, it seems that the empty string `"" ` acts as â€śundefinedâ€ť but I donâ€™t know if thatâ€™s really the case for all string attributes.

What about other attributes? Both `levels=nothing` and `levels=:auto` result in error, for example.

I wish that `attributeX = nothing` were always equivalent to â€śnot specifying `attributeX`â€ť. Currently, all I can think of is to use the named-tuple-splattering trick I show above in order to simulate `nothing`.