Specify digits in contour plot scale

I have a grid of contour plots. Depending on input, some subplots only have a single value on the z dimension. The problem is that the scale displays multiple digits, which decreases the size of all subplots in the grid. How can I control the number of digits displayed? I tried zticks, but that did not work. Thank you.

MWE:

using Plots 
x = .1:0.05:2

y = .1:0.05:1

X = repeat(reshape(x, 1, :), length(y), 1)

Y = repeat(y, 1, length(x))

Z = fill(.655848484848, size(X))

p1 = contour(x, y, Z, fill = true, zticks=[.65])

The folllowing works with Plots’ pyplot() backend (and also with pgfplotsx()):

using Plots; pyplot()
x = y = .1:0.05:4
Z = sqrt.(x' .* y)
num = round(π, digits=2)
contourf(x, y, Z, colorbar_ticks=[num])

But not sure if that will solve your ultimate problem of spacing between subplots.

Hi Rafael. Thanks for your response. Strangely, this solution does not work when the Z dimension only has a single unique value. Here is an example:

using Plots

pyplot()

x = .1:0.05:2

y = .1:0.05:1

X = repeat(reshape(x, 1, :), length(y), 1)

Y = repeat(y, 1, length(x))

Z = fill(.655848484848, size(X))

p1 = contour(x, y, Z, fill = true, colorbar_ticks=[.65])

It is certainly an improvement because it does not have a long number, but is there a way to still show it somehow?

Please check if this could be OK:

num = 0.655848484848
num = round(num, digits=3)
contourf(x, y, Z, colorbar_ticks=[], colorbar_title=string(num))
1 Like

Thanks Rafael! I think this is close enough. If someone else has an idea about rotating the colorbar title, I would be interested in that. I tried zguidefontrotation = 90, but to no avail.