I’m plotting a 2D field with contourf
. The field has positive and negative values and so I use one divergent colormap or another and with a symmetric contouring like levels=-10:2:10
.
The problem I face now is that I need to delete the zero-value contour lines. Setting the levels like levels=-11:2:11
is one way, but with this strategy, it’s harder to get “clean” numbers for contour levels. I want ticks on the colorbar where the contour levels are: something like Colorbar( . . . ; ticks=levels)
.
What I want is a white or gray region around zero, as in the attached plot. The colorbar is sort of ugly but as a scientific presentation, it’s sometimes better to prevent the reader from focusing on the zero contour lines. I mean, we sometimes want to ignore small absolute values.
This problem becomes significant when you plot a set of plots for a movie. You want to keep the contour levels constant across the frames and sometimes a large fraction of the frame is occupied by near-zero values, for which you want to show just solid white or gray, without zero-level contour lines.
So, are there divergent colormaps with a white or gray “region” around the center?
If not, what’s the best way to edit an existing colormap? (It would be nice if the modification can be done within the Julia program to plot the contour maps.)
A sample Julia code to illustrate the problem:
using CairoMakie
nx = 30
ny = 20
xax = (-nx/2):(nx/2)
yax = (-ny/2):(ny/2)
myfield = rand(nx+1,ny+1) .- 0.5
fig = Figure()
ax = Axis(fig[1,1])
c = contourf!(xax,yax,myfield;levels=-5:1:5,colormap=:RdBu)
Colorbar(fig[1,2], c)
save("tmp3.png", fig)