Colorbar of a Contour Plot

prconlin
Tue, 12 Aug 2025 16:30:11 +0000
Visualization

Hello,

I have a matrix of discrete values, and I would like to plot it as a contour plot instead of a heatmap, because reasons. This works well enough, except that the colorbar is strange and I can’t find a way to correct it.

The MWE:

using Plots # gr
x = rand(1:10, 100, 100)
contour(x)

For my use case, a discrete colorbar with bins would be ideal (see here for reference). I would also be fine with a continuous colorbar, which is the default for heatmaps in GR. But instead I get this strange bar with discrete levels that do not correspond to the step size. Moreover, the bins are not colored in. Using contourf() or fill = true fills in the bins, but they still do not correspond to the step size.

I’ve tried playing around with the following attributes, without success:
levels, colorbar_formatter, colorbar_ticks, and colorbar_continous_values

Any help would be appreciated,
Thanks

4 posts - 2 participants