Skip to content

Commit

Permalink
Movie example in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Feb 3, 2023
1 parent 6a3be7a commit 0f74f08
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ end
````

### Movies
Currently, these can be recorded with Makie and Plots backends both from
the REPL and Pluto notenooks. MP4 files and gifs can be created.
Currently, these can be recorded with GLMakie, CairoMakie and Plots backends both from
the REPL and Pluto notebooks. MP4 files and gifs can be created.
PyPlot possibly will follow.

This shows the animated graphic in the REPL (essentially the same as above)
and creates an embedded video in a Pluto notebook.
and creates an embedded video in a Pluto notebook:
````
vis=GridVisualizer(Plotter=GLMakie)
vis=GridVisualizer(Plotter=Plots)
movie(vis) do vis
for i=1:N
function=calculate(i)
Expand All @@ -75,7 +75,7 @@ movie(vis) do vis
end
````

To save to a file, use
To save to a file instead of showing in a notebooks or from the REPL , use:
````
vis=GridVisualizer(Plotter=CairoMakie)
movie(vis, file="video.mp4") do vis
Expand Down Expand Up @@ -120,8 +120,9 @@ and all plotting functions will do nothing.
- 'i': some level of interactive control
- '(y)': availability only on rectangular grids
- 'p': planned
- 'n': probably not, also in the future

| | PyPlot | GLMakie | PlutoVista | Plots | VTKView |
| | PyPlot | Makie | PlutoVista | Plots | VTKView |
|----------------|--------|---------|------------|-------|---------|
| scalarplot, 1D | y | y | y,i | y | y |
| vectorplot, 1D | y | y | y | y | y |
Expand All @@ -130,10 +131,11 @@ and all plotting functions will do nothing.
| vectorplot, 2D | y | y | y | y | |
| streamplot, 2D | y | p | p | | |
| gridplot, 2D | y | y,i | y | (y) | y,i |
| scalarplot, 3D | y | y,i | y,i | | y,i |
| gridplot, 3D | y | y,i | y,i | | y,i |
| vectorplot, 3D | p | p | p | | |
| streamplot, 3D | | p | p | | |
| scalarplot, 3D | y | y,i | y,i | n | y,i |
| gridplot, 3D | y | y,i | y,i | n | y,i |
| vectorplot, 3D | p | p | p | n | |
| streamplot, 3D | | p | p | n | |
| movie | p | y | n | y | |



Expand Down
4 changes: 4 additions & 0 deletions docs/makeplots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@ function makeplots(picdir; Plotter=GLMakie, extension="png")
println("grid1d")


fname=joinpath(picdir,"plotting_video."*"gif")
p=plotting_movie(;filename=fname,Plotter=Plotter)
@test isfile(fname)
println("plotting_video")
true
end
19 changes: 19 additions & 0 deletions examples/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ function plotting_stream2d(; Plotter = default_plotter(), kwargs...)
end
# ![](plotting_stream2d.svg)

# ### Movie
# Movies can contain any of the previous plots.
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
grid=simplexgrid(X,X)
movie(vis,file=filename) do vis
for t=0:0.1:10
f=map( (x,y)-> sin(x-t)*cos(y-t),grid)
g=map( (x,y)-> sin(t)*sin(x)*cos(y),grid)
scalarplot!(vis[1,1],grid,f,clear=true, title="t=$(t)",limits=(-1,1),levels=7,colormap=:hot)
scalarplot!(vis[1,2],grid,g,clear=true, title="t=$(t)",limits=(-1,1),levels=7,colormap=:hot)
reveal(vis)
end
end
end
# ![](plotting_video.gif)


# ## Multiscene plots
# We can combine multiple plots into one scene according to
# some layout grid given by the layout parameter.
Expand Down
24 changes: 11 additions & 13 deletions examples/plutovista.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
### A Pluto.jl notebook ###
# v0.19.16
# v0.19.22

using Markdown
using InteractiveUtils

# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try
Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"),
"AbstractPlutoDingetjes")].Bonds.initial_value
catch
b -> missing
end
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
Expand Down Expand Up @@ -116,7 +111,7 @@ t4: $(@bind t4 PlutoUI.Slider(-10:0.1:10, default=0, show_value=true))

# ╔═╡ c1278fb2-3e75-445f-893a-b8b8a7e931d3
p = GridVisualizer(; resolution = (600, 200), dim = 1, legend = :lt);
p;


# ╔═╡ 661531f7-f740-4dd4-9a59-89ddff06ba5c
scalarplot!(p, X2, f2(t4); show = true, clear = true, color = :red, label = "t=$(t4)")
Expand Down Expand Up @@ -170,7 +165,6 @@ end

# ╔═╡ faa59bbd-df1f-4c62-9a77-c4752c6a6df4
vis = GridVisualizer(; resolution = (300, 300), dim = 2);
vis;

# ╔═╡ 6f1707ed-79ab-42dc-8ad8-d66a9e1a65b3
md"""
Expand Down Expand Up @@ -235,8 +229,10 @@ scalarplot!(p3d, g3, f3; levels = [flevel], xplanes = [xplane], yplanes = [yplan
levelalpha = 0.5)

# ╔═╡ d924d90d-4102-4ae8-b8de-254a17a5d4df
X4 = -1:0.1:1;
g4 = simplexgrid(X4, X4, X4);
begin
X4 = -1:0.1:1;
g4 = simplexgrid(X4, X4, X4);
end

# ╔═╡ 57ed5eea-bc1c-45eb-b4d3-dc63088db21a
scalarplot(g4, map((x, y, z) -> 0.01 * exp(-10 * (x^2 + y^2 + z^2)), g4); levels = 10)
Expand Down Expand Up @@ -348,8 +344,10 @@ md"""
"""

# ╔═╡ 6a3b2356-e8a1-45f8-8648-2eca09a7b258
XX = 0:0.1:1;
YY = 0:0.1:10;
begin
XX = 0:0.1:1;
YY = 0:0.1:10;
end

# ╔═╡ 608a5704-a84c-4c55-8642-ecddb275dc1b
scalarplot(XX, YY, (x, y) -> sin(4x) * 10 * y; aspect = 0.1, xlabel = "aaa",
Expand Down

2 comments on commit 0f74f08

@j-fu
Copy link
Member Author

@j-fu j-fu commented on 0f74f08 Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/76926

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.4 -m "<description of version>" 0f74f08f6dfc80ad3daf4161f0e3b586177a9c5b
git push origin v0.6.4

Please sign in to comment.