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

**URL:** <https://discourse.julialang.org/t/how-to-accurately-plot-3d-graph-with-very-high-peak-in-julia/116317>\
**Category:** General Usage\
**Tags:** glmakie, graphs\
**Created:** [June 27, 2024, 5:07pm UTC](https://discourse.julialang.org/t/how-to-accurately-plot-3d-graph-with-very-high-peak-in-julia/116317 "2024-06-27T17:07:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vinh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinh/32/210077_2.png) [@Vinh](https://discourse.julialang.org/u/Vinh)\
**Post date:** [June 27, 2024, 5:07pm UTC](https://discourse.julialang.org/t/how-to-accurately-plot-3d-graph-with-very-high-peak-in-julia/116317/1 "2024-06-27T17:07:27Z")

</div>

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.

```julia
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

```

 ![3d_plot](https://global.discourse-cdn.com/julialang/original/3X/1/9/191cc4d346891721669c384a1e495f9c587b5f0b.png)

---

<div class="post-metadata">

**Author:** ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)\
**Post date:** [June 27, 2024, 5:33pm UTC](https://discourse.julialang.org/t/how-to-accurately-plot-3d-graph-with-very-high-peak-in-julia/116317/2 "2024-06-27T17:33:43Z")

</div>

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

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

```

**Edit:**  
The [docs for `Axis3`](https://docs.makie.org/stable/reference/blocks/axis3) don’t reference `{x,y,z}scale` attributes, but the [docs for `Axis`](https://docs.makie.org/stable/reference/blocks/axis#xscale) 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`.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [June 27, 2024, 5:59pm UTC](https://discourse.julialang.org/t/how-to-accurately-plot-3d-graph-with-very-high-peak-in-julia/116317/3 "2024-06-27T17:59:23Z")

</div>

```julia
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.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/e/8ecfa5c5a94f8ff56ed392ce9b98f09117d6c436.png)

---

<div class="post-metadata">

**Author:** ![Vinh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinh/32/210077_2.png) [@Vinh](https://discourse.julialang.org/u/Vinh)\
**Post date:** [June 28, 2024, 1:35am UTC](https://discourse.julialang.org/t/how-to-accurately-plot-3d-graph-with-very-high-peak-in-julia/116317/4 "2024-06-28T01:35:40Z")

</div>

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.

 ![DoThiHam](https://global.discourse-cdn.com/julialang/original/3X/6/2/62df1291c9af62c8c41a60aa7add3a562858e7e1.png)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [June 28, 2024, 9:59pm UTC](https://discourse.julialang.org/t/how-to-accurately-plot-3d-graph-with-very-high-peak-in-julia/116317/5 "2024-06-28T21:59:08Z")

</div>

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.
