Micah P. Dombrowski / Jul 23 2020
Remix of Python by Nextjournal
Makie Examples
Build environment w/ all Makie backends.
]add Makie, CairoMakie, GLMakie; precompile
253.2s
Julia Makie (Julia)
using WGLMakie, GLMakie, CairoMakie, AbstractPlotting
40.7s
Julia Makie (Julia)
WGLMakie
The WGLMakie backend uses WebGL to render interactive 2D and 3D output in the browser. Because it is browser-side, its performance will depend on the local machine's hardware. Simpler figures will generally load and perform faster.
using WGLMakie, AbstractPlotting
WGLMakie.activate!()
scene = Scene(resolution=(550,550))
N = 30
function xy_data(x, y)
r = sqrt(x^2 + y^2)
r == 0.0 ? 1f0 : (sin(r)/r)
end
lspace = range(-10, stop = 10, length = N)
z = Float32[xy_data(x, y) for x in lspace, y in lspace]
r = range(0, stop = 3, length = N)
surface!(scene,
r, r, z,
colormap = :Spectral
)
scene
1.0s
CairoMakie & WGLMakie (Julia)
Julia Makie
CairoMakie
The CairoMakie backend is for creating 2D, publication-quality, non-interactive output.
using CairoMakie, AbstractPlotting
CairoMakie.activate!()
Attributes(font = "Open Sans", resolution = (600, 500))
#An example is taken from the site: https://makie.juliaplots.org/stable/basic-tutorials.html
x=range(0,stop=2pi,length=40)
f(x)=sin.(x)
y=f(x)
lines(x,y,color=:blue)
90.2s
CairoMakie & WGLMakie (Julia)
Julia Makie
GLMakie
The GLMakie backend renders figures using a server-side GPU. The output figures are static files, but can be animated by rendering frames and outputting to gif or video files.
using Makie, GLMakie, AbstractPlotting
GLMakie.activate!()
vx = -1:0.01:1
vy = -1:0.01:1
f(x, y) = (sin(x*10) + cos(y*10)) / 4
scene = Scene(resolution = (500, 500))
# One way to style the axis is to pass a nested dictionary / named tuple to it.
surface!(scene, vx, vy, f, axis = (frame = (linewidth = 2.0,),))
psurf = scene[end] # the surface we last plotted to scene
# One can also directly get the axis object and manipulate it
axis = scene[Axis] # get axis
# You can access nested attributes likes this:
axis[:names, :axisnames] = ("\\bf{ℜ}[u]", "\\bf{𝕴}[u]", " OK\n\\bf{δ}\n γ")
tstyle = axis[:names] # or just get the nested attributes and work directly with them
tstyle[:textsize] = 10
tstyle[:textcolor] = (:red, :green, :black)
tstyle[:font] = "helvetica"
psurf[:colormap] = :RdYlBu
wh = widths(scene)
t = text!(
campixel(scene),
"Multipole Representation of first resonances of U-238",
position = (wh[1] / 2.0, wh[2] - 20.0),
align = (:center, :center),
textsize = 20,
font = "helvetica",
raw = :true
)
c = lines!(scene, Circle(Point2f0(0.1, 0.5), 0.1f0), color = :red, offset = Vec3f0(0, 0, 1))
scene
#update surface
# TODO explain and improve the situation here
psurf.converted[3][] = f.(vx .+ 0.5, (vy .+ 0.5)')
Makie.save("/results/plot.png", scene)
69.7s
GLMakie (Julia)
Julia Makie