Skip to content

Commit

Permalink
Multiple plots per visualizer via HypertextLiteral
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Nov 5, 2021
1 parent 315f1e5 commit 193f9f9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Plot appearance can be tweaked by a number of
[keyword arguments](https://j-fu.github.io/GridVisualize.jl/dev/api/#GridVisualize.available_kwargs).

### Plotters
Plotters can be e.g. Plots, GLMakie, PlutoVista - we pass the module exported
Plotters can be e.g. Plots, PyPlot, GLMakie, PlutoVista - we pass the module exported
by the package. Different plotters can be used at the same time.

### Multiple plots in one plotting window
Expand All @@ -44,7 +44,6 @@ gridplot!(vis[1,1],grid)
scalarplot!(vis[1,2],grid,function)
reveal(vis)
````
(not supported by PlutoVista)

### Transient plots

Expand Down Expand Up @@ -77,8 +76,6 @@ gridplot!(vis[1,1],grid)
scalarplot!(vis[1,2],grid,function)
```

When the package is loaded, the default plotter is determined by the installed
plotting package (using Requires.jl).


### Switching off plotting
Expand Down
44 changes: 37 additions & 7 deletions examples/plutovista.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ begin
Pkg.activate(".testenv")
Pkg.add("Revise")
using Revise
Pkg.add(["PlutoUI","ExtendableGrids"])
Pkg.add(["PlutoUI","ExtendableGrids","HypertextLiteral"])
Pkg.develop(["GridVisualize","PlutoVista"])
end

Expand All @@ -30,14 +30,15 @@ using PlutoVista
using GridVisualize
using ExtendableGrids
using PlutoUI
using HypertextLiteral
GridVisualize.default_plotter!(PlutoVista)
end

# ╔═╡ f6205299-d097-4e78-8488-b088475191f6
let
if isfile("plotting.jl")
include("plotting.jl")
plotting_multiscene(Plotter=PlutoVista,resolution=(650,350))
plotting_multiscene(Plotter=PlutoVista,resolution=(650,300))
end
end

Expand Down Expand Up @@ -285,13 +286,39 @@ md"""
let vis=GridVisualizer(resolution=(600,600),layout=(2,2))
g2=simplexgrid(X,X)
g3=simplexgrid(X,X,X)
scalarplot!(vis[1,1],X,sin.(2*X))
scalarplot!(vis[1,2],g2,(x,y)->sin(x)*cos(y))
scalarplot!(vis[2,1],g2,(x,y)->sin(x)*cos(y),colormap=:hot)
scalarplot!(vis[2,2],g2,(x,y)->sin(x)*cos(y),colormap=:hot, backend=:plotly)
scalarplot!(vis[1,1],X,sin.(2*X))
scalarplot!(vis[1,2],g2,(x,y)->sin(x)*cos(y))
scalarplot!(vis[2,1],g2,(x,y)->sin(x)*cos(y),colormap=:hot)
scalarplot!(vis[2,2],g2,(x,y)->sin(x)*cos(y),colormap=:hot, backend=:plotly)
reveal(vis)
end

# ╔═╡ 6915cc3e-ad9b-4721-9933-884cfc68a25a
md"""
It is also possible to directly arrange plots using HypertextLiteral:
"""

# ╔═╡ 49db8b25-50ce-4fb4-bea2-de8abfb53c56
X0=0:0.25:10

# ╔═╡ 15f4eeb3-c42e-449c-9161-f1df66de6cef
htl"""
<div style= "width: 800px; display: inline-block; white-space:nowrap;">
<div style= "display: inline-block;">
$(scalarplot(X0,X0,X0, (x,y,z)->(sin(x)*sin(y)*sin(z)*sqrt(x*y*z)),resolution=(200,200),colormap=:rainbow))
</div>
<div style= "display: inline-block;">
$(scalarplot(X0,X0,X0, (x,y,z)->(sin(0.1*x*y)*sin(z)),resolution=(200,200),colormap=:hot,backend=:plotly))
</div>
<div style= "display: inline-block;">
$(scalarplot(X0,X0, (x,y)->sin(0.1*x*y),resolution=(200,200),colormap=:summer))
</div>
<div style= "display: inline-block;">
$(scalarplot(X0, (x)->x*sin(2x),color=:red,resolution=(200,200),colormap=:summer))
</div>
</div>
"""

# ╔═╡ ba5111b8-0dca-42d2-970f-1e88f5392324
html"""<hr>"""

Expand Down Expand Up @@ -347,9 +374,12 @@ md"""
# ╟─4121e791-8785-472e-a706-7b9cefd36fd6
# ╠═e656dac5-466e-4c07-acfa-0478ad000cb2
# ╠═812af347-7606-4c54-b155-88322d20d921
# ╠═09998521-68b6-45b4-8c1d-ae73bbd431ad
# ╟─09998521-68b6-45b4-8c1d-ae73bbd431ad
# ╠═2d31f310-0d59-4ceb-9daf-61f447de3bb0
# ╠═f6205299-d097-4e78-8488-b088475191f6
# ╟─6915cc3e-ad9b-4721-9933-884cfc68a25a
# ╟─49db8b25-50ce-4fb4-bea2-de8abfb53c56
# ╠═15f4eeb3-c42e-449c-9161-f1df66de6cef
# ╟─ba5111b8-0dca-42d2-970f-1e88f5392324
# ╟─92bfccf7-abf1-47d5-8d8b-9ae9003ad1ac
# ╠═a98fae2c-9c3a-41c6-96f3-93d147f79e7b
16 changes: 8 additions & 8 deletions src/plutovista.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using HypertextLiteral
function initialize!(p::GridVisualizer,::Type{PlutoVistaType})
PlutoVista=p.context[:Plotter]
layout=p.context[:layout]
figres=(0.9*p.context[:resolution][1]/layout[2],0.9*p.context[:resolution][2]/layout[1])
figres=(p.context[:resolution][1]/layout[2],p.context[:resolution][2]/layout[1])
for I in CartesianIndices(layout)
ctx=p.subplots[I]
ctx[:figure]=PlutoVista.PlutoVistaPlot(resolution=figres)
Expand All @@ -25,33 +25,33 @@ function reveal(p::GridVisualizer,::Type{PlutoVistaType})
if l==1
subplots[1][:figure]
elseif l==2
@htl("""<div><div style= "width: $(p.context[:resolution][1])px; display: inline-block;">
@htl("""<div><div style=" display: inline-block;">
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[1][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[2][:figure])</div>
</div>""")
elseif l==3
@htl("""<div><div style= "width: $(p.context[:resolution][1])px; display: inline-block;">
@htl("""<div><div style=" display: inline-block;">
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[1][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[2][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[3][:figure])</div>
</div>""")
elseif l==4
@htl("""<div><div style= "width: $(p.context[:resolution][1])px; display: inline-block;">
@htl("""<div><div style=" display: inline-block;">
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[1][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[2][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[3][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[4][:figure])</div>
</div>""")
elseif l==5
@htl("""<div><div style= "width: $(p.context[:resolution][1])px; display: inline-block;">
@htl("""<div><div style=" display: inline-block;">
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[1][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[2][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[3][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[4][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[5][:figure])</div>
</div>""")
elseif l==6
@htl("""<div><div style= "width: $(p.context[:resolution][1])px; display: inline-block;">
@htl("""<div><div style=" display: inline-block;">
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[1][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[2][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[3][:figure])</div>
Expand All @@ -60,7 +60,7 @@ function reveal(p::GridVisualizer,::Type{PlutoVistaType})
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[6][:figure])</div>
</div>""")
elseif l==7
@htl("""<div><div style= "width: $(p.context[:resolution][1])px; display: inline-block;">
@htl("""<div><div style=" display: inline-block;">
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[1][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[2][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[3][:figure])</div>
Expand All @@ -70,7 +70,7 @@ function reveal(p::GridVisualizer,::Type{PlutoVistaType})
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[7][:figure])</div>
</div>""")
elseif l==8
@htl("""<div><div style= "width: $(p.context[:resolution][1])px; display: inline-block;">
@htl("""<div><div style=" display: inline-block;">
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[1][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[2][:figure])</div>
<div style= "width: $(figwidth)px; display: inline-block;">$(subplots[3][:figure])</div>
Expand Down

2 comments on commit 193f9f9

@j-fu
Copy link
Member Author

@j-fu j-fu commented on 193f9f9 Nov 5, 2021

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/48197

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.4.1 -m "<description of version>" 193f9f9e750552274b22106100e30f2fbc00b477
git push origin v0.4.1

Please sign in to comment.