Colormap logscale using Plot

I’m trying to build a 3D surface plot with color in log10 scale. I just want the color to be in the log10 scale NOT the actual values itself.

N = 51
x = range(-10, stop = 10, length = N)
y = x
f(x,y)=x^2+y^2
Plots.plot(x,y,f,st=:surface,color=:jet,camera=(25,65))

See below:

output

Here is the output with Logscale created using GNUPLOT.

1 Like

Check out the documentation. It is pretty

2 Likes

Thank you. The link really helped.

I have used log scale, but still unable to reproduce the chart from gnuplot.

using Plots
N = 51
x = range(-10, stop = 10, length = N)
y = x
f(x,y)=x^2+y^2
out = Plots.plot(x,y,f,st=:surface,color= cgrad(:jet,scale=log),camera=(25,65))
savefig(out,"out.png")

The key driving factor is z the need to included in cgrad. How would one modify z to get a replica of my original plot.

out

I figured it out:

using Plots
N = 51
x = range(-10, stop = 10, length = N)
y = x
f(x,y)=x^2+y^2
z  = [0.001,0.01,0.05,5,50,100,200]
out = Plots.plot(x,y,f,st=:surface,color= cgrad(:jet,z,scale=log),camera=(25,65))
savefig(out,"out.png")

It would be great if we can automatically estimate values z like gnuplot.

out1

You can do e.g.

z = 10 .^ (1:0.01:2)
2 Likes

I’m trying to do this with contours but it’s not working.

using Plots; pyplot()

f(x, y) = exp(x^2 + y^2)
x = range(-3, 3, length=100)'
y = range(-3, 3, length=100)
z = @. f(x, y)
zc = 10 .^ range(log10(minimum(z)), log10(maximum(z)), length=100)
contourf(x, y, z, colorbar_scale=:log10, color=cgrad(:turbo, zc, scale=:log10))

But most of the plot is blue, when it should be a more gradual gradient. In other words, I’d like to have something like this, or this, where each level is an order of magnitude. Is this possible?

You can play with plot()'s keyword arguments levels and colorbar_ticks to produce discrete or smooth contour maps:

1 Like

Ok I figured it out. Unfortunately it requires plotting \log z instead of z directly…code below for reference.

using Plots, LaTeXStrings
pyplot()

h(x, y) = exp(x^2 + y^2)

x = range(-3, 3, length=100) |> adjoint
y = range(-3, 3, length=100)
z = @. h(x, y)

tv = 0:8
tl = [L"10^{%$i}" for i in tv]
contourf(x, y, log10.(z), color=:turbo, levels=8, colorbar_ticks=(tv, tl), 
    aspect_ratio=:equal,
    title=L"\exp(x^{2} + y^{2})", 
    xlabel=L"x", 
    ylabel=L"y")

Figure_1