# How to accurately plot 3D graph with very high peak in Julia?

As the title says, I’m plotting a graph with very high peaks, but the output is really weird at (x,y)=(0.5,0.5) with no peaks at around 5*10^11. I’m not really sure why that is.

``````using GLMakie
f(x, y) = y^2 / ((x - 0.5)^2 + 10^-12) + x^2 / ((y - 0.5)^2 + 10^-12)
x = range(start=0, stop=1, step=0.0001)
y = range(start=0, stop=1, step=0.0001)
z = [f(xi, yi) for xi in x, yi in y]
fig = Figure()
ax = Axis3(fig[1, 1])
surface!(ax, x, y, z, colormap = :viridis)
fig

``````

This looks like the perfect use case for a logarithmic-scale axis. I’m not sure how to do this off-hand in Makie but ChatGPT suggests the following might work

``````ax.scene.plots[1][:axis3].zscale = Makie.Scale(log10)
``````

Edit:
The docs for `Axis3` don’t reference `{x,y,z}scale` attributes, but the docs for `Axis` do include `{x,y}scale`. If those translate, then it looks like you might be able to just add `zscale=log` to the keyword arguments for `Axis3`.

1 Like
``````julia> 0.5 in 0.4997:0.0001:0.5003 # sanity checks of ranges
true

julia> in.(reshape(0.4997:0.0001:0.5003, 1, 7), Ref(range(start=0, stop=1, step=0.0001)) )
1×7 BitMatrix:
1  1  1  1  1  1  1

julia> f.(0.5, reshape(0.4997:0.0001:0.5003, 1, 7)) # 1 element doubles to peak
1×7 Matrix{Float64}:
2.49703e11  2.49806e11  2.49925e11  5.0e11  2.50125e11  2.50206e11  2.50303e11
``````

Maybe just trouble rendering very thin peaks, in this case 1 element. Screens that typically get up to 1920 pixels plausibly skip most of the 10001 values each dimension, and it doesn’t know what important values to keep. If this is the case, could try sharply narrowing the limits. Tossed the equation into Wolfram Alpha, the contour plot seems to confirm that the visible slabs widen enough to be rendered. Surface plot not shown because it cuts it off at z=300 no matter what.

1 Like

Your advice was very helpful to me. Setting step=0.005 have a peak but still not the right height unless I limits the x and y ranges.

Yeah, increasing the step to reduce the number of elements like that just about confirms it. Just a fundamental limitation, like not being able to spot a microbe without a microscope. A peak detection algorithm should not be affected by rendering resolution, just the data’s sampling rate, but I’ve never worked with one that works over 2 independent variables.