Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.15.3] - 2025-06-24
- Fixed bug with GLMakie based animated plots from the REPL
- Added examples for animated plots from the REPL

## [1.15.2] - 2025-06-24
- fixed a corner case in `compute_2d_rotation_matrix` leading to wrong coordinate transformation in 1D slice plots

Expand Down
11 changes: 6 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GridVisualize"
uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
version = "1.15.2"
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Patrick Jaap <patrick.jaap@wias-berlin.de>"]
version = "1.15.3"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand All @@ -26,18 +26,19 @@ MeshCat = "283c5d60-a78f-5afe-a0af-af636b173e11"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoVista = "646e1f28-b900-46d7-9d87-d554eb38a413"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
VTKView = "955f2c64-5fd0-11e9-0ad0-3332e913311a"
Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
VTKView = "955f2c64-5fd0-11e9-0ad0-3332e913311a"

[extensions]
GridVisualizeMakieExt = "Makie"
GridVisualizeVTKViewExt = "VTKView"
GridVisualizeMeshCatExt = "MeshCat"
GridVisualizePyPlotExt = "PyPlot"
GridVisualizePlotsExt = "Plots"
GridVisualizePlutoVistaExt = "PlutoVista"
GridVisualizePyPlotExt = "PyPlot"
GridVisualizeVTKViewExt = "VTKView"

[compat]
CairoMakie = "0.11, 0.12, 0.13, 0.14, 0.15"
ColorSchemes = "3"
Colors = "0.12,0.13,1"
DocStringExtensions = "0.8,0.9"
Expand All @@ -46,7 +47,7 @@ ExtendableGrids = "1.10"
GeometryBasics = "0.4.1, 0.5"
GridVisualizeTools = "3"
HypertextLiteral = "0.9"
Interpolations = "0.14, 0.15"
Interpolations = "0.14, 0.15, 0.16"
IntervalSets = "0.7"
LinearAlgebra = "1.6"
Makie = "0.21, 0.22.10, 0.23, 0.24"
Expand Down
83 changes: 70 additions & 13 deletions examples/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using Triangulate: Triangulate, TriangulateIO, triangulate
using Printf

# ### 1D grids
# See [`GridVisualize.gridplot`](@@ref).
function grid1d(; n = 50)
X = collect(0:(1 / n):1)
return g = simplexgrid(X)
Expand All @@ -30,6 +31,7 @@ end
# ![](plotting_grid1d.png)

# ### 2D grids
# See [`GridVisualize.gridplot`](@@ref).

function grid2d(; n = 20)
X = collect(0:(1 / n):1)
Expand All @@ -42,6 +44,7 @@ end
# ![](plotting_grid2d.png)

# ### 3D grids
# See [`GridVisualize.gridplot`](@@ref).
# The kwargs `xplane`, `yplane` and `zplane` which allow to control
# cutplanes which peel off some elements from the grid in 3d and allow to
# explore the inner triangulation.
Expand All @@ -61,6 +64,8 @@ end
# ## Function plots

# ### Function on 1D grid
# See [`GridVisualize.scalarplot`](@@ref).

function func1d(; n = 50)
g = grid1d(; n = n)
return g, map(x -> sinpi(2 * x[1]), g)
Expand All @@ -72,7 +77,9 @@ function plotting_func1d(; Plotter = default_plotter(), kwargs...)
end
# ![](plotting_func1d.png)


# ### Function on 2D grid
# See [`GridVisualize.scalarplot`](@@ref).
function func2d(; n = 30)
g = grid2d(; n = n)
return g, map((x, y) -> sinpi(2 * x) * sinpi(3.5 * y), g)
Expand All @@ -84,9 +91,10 @@ function plotting_func2d(; Plotter = default_plotter(), kwargs...)
end
# ![](plotting_func2d.png)


# ### Function on 3D grid
# See [`GridVisualize.scalarplot`](@@ref).
#
# Plotting a function then goes as follows:
# `xplane`, `yplane` and `zplane` now define cut planes where
# the function projection is plotted as a heatmap.
# The additional `flevel` keyword argument allows
Expand Down Expand Up @@ -114,6 +122,7 @@ end

# ## d-1 dim slice in d-dim data
# ### 2D slice of a 3D grid
# See [`GridVisualize.scalarplot`](@@ref).
#
# You can plot a 2D slice of a function defined on a
# 3D grid by providing a `slice` key word argument which
Expand All @@ -136,6 +145,7 @@ end

# ### 1D line of a 2D grid
#
# See [`GridVisualize.scalarplot`](@@ref).
# You can plot a 1D line of a function defined on a
# 2D grid by providing a `slice` key word argument which
# describes a line equation of a fixed value to one axis.
Expand All @@ -155,18 +165,9 @@ end
# ![](plotting_line2d.png)


#
# Plotting a function then goes as follows:
# `xplane`, `yplane` and `zplane` now define cut planes where
# the function projection is plotted as a heatmap.
# The additional `flevel` keyword argument allows
# to control an isolevel.
#
# For Makie and VTKView, the cutplane values and the flevel can be controlled interactively.


# ## Vector and stream plots
# ### 2D vector
# See [`GridVisualize.vectorplot`](@@ref).
function vec2d(; n = 20)
g = grid2d(; n = n)
return g,
Expand All @@ -183,15 +184,70 @@ end
# ![](plotting_vec2d.png)

# ### 2D stream
# See [`GridVisualize.streamplot`](@@ref).
# Stream plots are currently only available with PyPlot and Makie
function plotting_stream2d(; Plotter = default_plotter(), n = 50, kwargs...)
g, f = vec2d(; n = n)
return GridVisualize.streamplot(g, f; Plotter = Plotter, rasterpoints = 20, kwargs...)
end
# ![](plotting_stream2d.png)

# ### Movie
# ## Animation
# Animation examples work in the REPL. They are useful for in-situ visualization
# of evolving calculation data. For the creation of videos/movies, see the [Movie](@@ref) example.

# ### Animation of function on 1D grid
function anim_func1d(; Plotter = default_plotter(), kwargs...)
step = 0.01
if ismakie(Plotter)
step = 0.0001
end
g = grid1d(; n = 50)
vis = GridVisualizer(; Plotter, kwargs...)
for t in 0:step:1
f = map(x -> sinpi(3 * (x[1] - t)), g)
scalarplot!(vis, g, f, title = "t=$(t)", show = true)
end
return nothing
end

# ### Animation of function on 2D grid
function anim_func2d(; Plotter = default_plotter(), kwargs...)
step = 0.05
if ismakie(Plotter)
step = 0.005
end
g = grid2d(; n = 30)
vis = GridVisualizer(; Plotter, kwargs...)
for t in 0:step:1
f = map(x -> sinpi(3 * (x[1] - t) * (2 * x[2] - 2t)), g)
scalarplot!(vis, g, f, title = "t=$(t)", show = true)
end
return nothing
end

# ### Animation of function on 3D grid
function anim_func3d(; Plotter = default_plotter(), kwargs...)
step = 0.05
if ismakie(Plotter)
step = 0.005
end
g = grid3d(; n = 15)
vis = GridVisualizer(; Plotter, kwargs...)
for t in 0:step:1
f = map(x -> sinpi(3 * (x[1] - t)) * sinpi(2 * x[2] - 2t) * cospi(x[3] - t / 2), g)
scalarplot!(vis, g, f, title = "t=$(t)", show = true)
end
return nothing
end


# ## Movie
# Movies can contain any of the previous plots.
# Best created with GLMakie or CairoMakie. File formats are gif and mp4.
# See [`GridVisualize.movie`](@@ref)
# See the [Animation](@@ref) examples
# for in-situ visualization of calculation results in the REPL.
function plotting_movie(; filename = "plotting_video.gif", Plotter = default_plotter())
vis = GridVisualizer(; Plotter = Plotter, size = (600, 200), layout = (1, 2))
X = 0:0.2:10
Expand Down Expand Up @@ -385,6 +441,7 @@ end
# ![](plotting_jfunc3d.png)

# ## Custom plots
# See [`GridVisualize.customplot!`](@@ref)
function plotting_custom(; Plotter = default_plotter(), kwargs...)
vis = GridVisualizer(; Plotter = Plotter)
grid = grid2d()
Expand All @@ -401,7 +458,7 @@ end

# ## TriangulateIO
#
# GridVisualize comes with [`GridVisualize.plot_triangulateio`](@ref), a method to plot the input/output
# GridVisualize comes with [`GridVisualize.plot_triangulateio`](@@ref), a method to plot the input/output
# struct of the Triangle mesh generator, provided by the [Triangulate.jl](https://github.com/JuliaGeometry/Triangulate.jl) wrapper.
# Supported are PyPlot and Makie backends.
#
Expand Down
2 changes: 2 additions & 0 deletions ext/GridVisualizeMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grids, parentgrid
y = ctx[:iyplanes],
z = ctx[:izplanes],
l = ctx[:levels],
c = ctx[:colorbarticks],
t = ctx[:title],
)
end
Expand All @@ -1460,6 +1461,7 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grids, parentgrid
y = ctx[:iyplanes],
z = ctx[:izplanes],
l = ctx[:levels],
c = ctx[:colorbarticks],
t = ctx[:title],
)
end
Expand Down
Loading