# Contour plot on Structured grid using Meshes.jl

**URL:** <https://discourse.julialang.org/t/contour-plot-on-structured-grid-using-meshes-jl/123854>\
**Category:** General Usage\
**Tags:** glmakie, meshes, cairomakie\
**Created:** [December 15, 2024, 6:48am UTC](https://discourse.julialang.org/t/contour-plot-on-structured-grid-using-meshes-jl/123854 "2024-12-15T06:48:52Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [December 15, 2024, 6:48am UTC](https://discourse.julialang.org/t/contour-plot-on-structured-grid-using-meshes-jl/123854/1 "2024-12-15T06:48:52Z")

</div>

In Julia i am using Meshes.jl and GLMakie.jl .  
I am using **x** , **z** , **alfsurf** and **psi** variables of size (109,50) each.  
I input them to StructuredGrid() function which creates a structured grid of size (108,49).

```julia
using Meshes, GLMakie

x = include("x.jl")
z = include("z.jl")
psi = include("psi.jl")
alfsurf = include("alfsurf.jl")

grd = StructuredGrid(x, z)

function safe_log(x)
	x == 0 ? 1 : log(x)
end
z_log = safe_log.(vec(alfsurf))
fig, ax, plt = Meshes.viz(grd, color=z_log, colorscheme=:jet)
contour!(plt,grd, psi, levels =15,color=:red)

```

How can i plot contours of psi although my code plots heatmap of alfsurf correctly ? Data of variables x, z, psi and alfsurf is in attached files.  
[alfsurf.jl](https://discourse.julialang.org/uploads/short-url/tbOZ4wV6jsvVWjRvhBGibzCLuZu.jl) (27.2 KB)  
[psi.jl](https://discourse.julialang.org/uploads/short-url/27ssQ2AKWVmD6svGyXUwULS6g9w.jl) (103.5 KB)  
[x.jl](https://discourse.julialang.org/uploads/short-url/jdmXMZCaxdfKpNDOYLq7a2gvBlU.jl) (98.8 KB)  
[z.jl](https://discourse.julialang.org/uploads/short-url/1b9IkQCrGebxu2S1zmL2KIzxhJi.jl) (97.5 KB)

I got error message shown below:

> ERROR: BoundsError: attempt to access 2-element Vector{Observable} at index [1:3]  
> Stacktrace:  
> [1] throw\_boundserror(A::Vector{Observable}, I::Tuple{UnitRange{Int64}})  
> @ Base ./essentials.jl:14  
> [2] checkbounds  
> @ ./abstractarray.jl:699 [inlined]  
> [3] getindex  
> @ ./array.jl:936 [inlined]  
> [4] getindex  
> @ ~/.julia/packages/MakieCore/05FeT/src/attributes.jl:184 [inlined]  
> [5] plot!(plot::Plot{contour, Tuple{StructuredGrid{𝔼{…}, CoordRefSystems.Cartesian2D{…}, 2, Tuple{…}}, Matrix{Float64}}})  
> @ Makie ~/.julia/packages/Makie/tjqse/src/basic\_recipes/contours.jl:212  
> [6] connect\_plot!(parent::Plot{viz, Tuple{StructuredGrid{…}}}, plot::Plot{contour, Tuple{StructuredGrid{…}, Matrix{…}}})  
> @ Makie ~/.julia/packages/Makie/tjqse/src/interfaces.jl:395  
> [7] plot!(scene::Plot{viz, Tuple{StructuredGrid{…}}}, plot::Plot{contour, Tuple{StructuredGrid{…}, Matrix{…}}})  
> @ Makie ~/.julia/packages/Makie/tjqse/src/interfaces.jl:412  
> [8] \_create\_plot!(::Function, ::Dict{…}, ::Plot{…}, ::StructuredGrid{…}, ::Vararg{…})  
> @ Makie ~/.julia/packages/Makie/tjqse/src/figureplotting.jl:391  
> [9] contour!(::Plot{viz, Tuple{StructuredGrid{…}}}, ::Vararg{Any}; kw::@Kwargs{levels::Int64, color::Symbol})  
> @ Makie ~/.julia/packages/MakieCore/05FeT/src/recipes.jl:505  
> [10] top-level scope  
> @ REPL[22]:1  
> Some type information was truncated. Use `show(err)` to see complete types.

---

_[View the full topic](https://discourse.julialang.org/t/contour-plot-on-structured-grid-using-meshes-jl/123854)._
