diff --git a/Project.toml b/Project.toml index 834b60acd..5fa9020d1 100644 --- a/Project.toml +++ b/Project.toml @@ -48,7 +48,7 @@ JLD2 = "0.4.33" JSON = "0.21.3" LinearAlgebra = "1.9" LinearMaps = "3.11.0" -Makie = "0.19.8, 0.20.0" +Makie = "0.20.0" OffsetArrays = "1.10.8" Optim = "1.7.6" Printf = "1.9" diff --git a/docs/make.jl b/docs/make.jl index 3ba988f48..fc37c456b 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,6 +5,9 @@ using Sunny, GLMakie, WriteVTK # Load packages to enable Documenter references isdraft = false # set `true` to disable cell evaluation +# Generate high resolution GLMakie images (two pixels per size "unit") +Makie.set_theme!(; GLMakie=(; px_per_unit=2)) + # Remove existing Documenter `build` directory build_path = joinpath(@__DIR__, "build") isdir(build_path) && rm(build_path; recursive=true) diff --git a/docs/src/versions.md b/docs/src/versions.md index 0d6002111..3bf94ca39 100644 --- a/docs/src/versions.md +++ b/docs/src/versions.md @@ -8,6 +8,9 @@ tutorial. * Remove internal functions `*_primitive_crystal`. Instead, it is recommended to use the conventional unit cell, and later call [`reshape_supercell`](@ref). +* Require Makie 0.20. An important new feature is resolution-independent scaling + of font sizes. New figures expect `size` instead of `resolution`, and no + longer accept `rescale`. ## v0.5.6 (Nov 8, 2023) diff --git a/examples/03_LLD_CoRh2O4.jl b/examples/03_LLD_CoRh2O4.jl index 74e026c49..1b5f3fcd1 100644 --- a/examples/03_LLD_CoRh2O4.jl +++ b/examples/03_LLD_CoRh2O4.jl @@ -44,7 +44,7 @@ for _ in 1:1000 step!(sys, langevin) push!(energies, energy_per_site(sys)) end -plot(energies, color=:blue, figure=(resolution=(600,300),), axis=(xlabel="Time steps", ylabel="Energy (meV)")) +plot(energies, color=:blue, figure=(size=(600,300),), axis=(xlabel="Time steps", ylabel="Energy (meV)")) # Thermal fluctuations are apparent in the spin configuration. diff --git a/examples/04_GSD_FeI2.jl b/examples/04_GSD_FeI2.jl index d887d2580..f1284321a 100644 --- a/examples/04_GSD_FeI2.jl +++ b/examples/04_GSD_FeI2.jl @@ -389,7 +389,7 @@ params.binstart[2], params.binend[2] = -2 * sqrt(3/4), 2 * sqrt(3/4) ## Re-compute in the new coordinate system is, counts = intensities_binned(sc,params,new_formula) -fig = Figure(; resolution=(1200,500))#hide +fig = Figure(; size=(600,250))#hide ax_right = Axis(fig[1,3];#hide title="ω≈$(round(target_ω, digits=2)) meV with Δω=0.3 meV (Binned)", aspect=true,#hide xlabel = "[H, -1/2H, 0]"#hide diff --git a/examples/06_CP2_Skyrmions.jl b/examples/06_CP2_Skyrmions.jl index 848f4f79b..a014db410 100644 --- a/examples/06_CP2_Skyrmions.jl +++ b/examples/06_CP2_Skyrmions.jl @@ -45,19 +45,19 @@ J1 = -1 # Nearest-neighbor ferromagnetic J2 = (2.0/(1+√5)) # Tune competing exchange to set skyrmion scale length Δ = 2.6 # Exchange anisotropy -ex1 = J1 * [1.0 0.0 0.0; - 0.0 1.0 0.0; - 0.0 0.0 Δ] -ex2 = J2 * [1.0 0.0 0.0; - 0.0 1.0 0.0; - 0.0 0.0 Δ] +ex1 = J1 * [1 0 0; + 0 1 0; + 0 0 Δ] +ex2 = J2 * [1 0 0; + 0 1 0; + 0 0 Δ] set_exchange!(sys, ex1, Bond(1, 1, [1, 0, 0])) set_exchange!(sys, ex2, Bond(1, 1, [1, 2, 0])) # Next we add the external field, h = 15.5 -field = set_external_field!(sys, [0.0 0.0 h]) +field = set_external_field!(sys, [0, 0, h]) # and finally an easy-plane single-ion anisotropy, @@ -92,7 +92,7 @@ integrator = Langevin(Δt; kT, λ) # different times during the quenching process by copying the `coherents` field # of the `System`. -τs = [4., 16, 256] # Times to record snapshots +τs = [4, 16, 256] # Times to record snapshots frames = [] # Empty array to store snapshots for i in eachindex(τs) dur = i == 1 ? τs[1] : τs[i] - τs[i-1] # Determine the length of time to simulate @@ -120,8 +120,8 @@ function sun_berry_curvature(z₁, z₂, z₃) return angle(n₁ * n₂ * n₃) end -plot_triangular_plaquettes(sun_berry_curvature, frames; resolution=(1800,600), - offset_spacing=10, texts = ["\tt = "*string(τ) for τ in τs], text_offset = (0.0, 6.0) +plot_triangular_plaquettes(sun_berry_curvature, frames; size=(600,200), + offset_spacing=10, texts=["\tt = "*string(τ) for τ in τs], text_offset=(0, 6) ) # The times are given in $\hbar/|J_1|$. The white diff --git a/examples/extra/Plotting/plotting2d.jl b/examples/extra/Plotting/plotting2d.jl index 9742c38e2..e7a16e5d9 100644 --- a/examples/extra/Plotting/plotting2d.jl +++ b/examples/extra/Plotting/plotting2d.jl @@ -116,7 +116,7 @@ function plot_triangular_plaquettes(f, frames; end poly!(ax, pgons; color, colormap, colorrange) if !isnothing(texts) - text!(ax, v₀[1] - text_offset[1], v₀[2] - text_offset[2]; text=texts[i], fontsize=36) + text!(ax, v₀[1] - text_offset[1], v₀[2] - text_offset[2]; text=texts[i], fontsize=14) end end return fig diff --git a/ext/PlottingExt.jl b/ext/PlottingExt.jl index f2fea8ac7..29f9bffa1 100644 --- a/ext/PlottingExt.jl +++ b/ext/PlottingExt.jl @@ -213,8 +213,8 @@ Plot the spin configuration defined by `sys`. Optional parameters are: Calling `notify` on the return value will animate the figure. """ -function Sunny.plot_spins(sys::System; resolution=(768, 512), show_axis=false, kwargs...) - fig = Makie.Figure(; resolution) +function Sunny.plot_spins(sys::System; size=(768, 512), show_axis=false, kwargs...) + fig = Makie.Figure(; size) ax = Makie.LScene(fig[1, 1]; show_axis) notifier = Makie.Observable(nothing) plot_spins!(ax, sys; notifier, kwargs...) @@ -251,7 +251,7 @@ Like [`plot_spins`](@ref) but will draw into the given Makie Axis, `ax`. =# function plot_spins!(ax, sys::System; notifier=Makie.Observable(nothing), arrowscale=1.0, stemcolor=:lightgray, color=:red, colorfn=nothing, colormap=:viridis, colorrange=nothing, show_cell=true, orthographic=false, - ghost_radius=0, rescale=1.0, dims=3) + ghost_radius=0, dims=3) if dims == 2 sys.latsize[3] == 1 || error("System not two-dimensional in (a₁, a₂)") elseif dims == 1 @@ -263,11 +263,11 @@ function plot_spins!(ax, sys::System; notifier=Makie.Observable(nothing), arrows # Show bounding box of magnetic supercell in gray (this needs to come first # to set a scale for the scene in case there is only one atom). supervecs = sys.crystal.latvecs * diagm(Vec3(sys.latsize)) - Makie.linesegments!(ax, cell_wireframe(supervecs, dims); color=:gray, linewidth=rescale*1.5) + Makie.linesegments!(ax, cell_wireframe(supervecs, dims); color=:gray, linewidth=1.5) # Bounding box of original crystal unit cell in teal if show_cell - Makie.linesegments!(ax, cell_wireframe(orig_crystal(sys).latvecs, dims); color=:teal, linewidth=rescale*1.5) + Makie.linesegments!(ax, cell_wireframe(orig_crystal(sys).latvecs, dims); color=:teal, linewidth=1.5) end # Infer characteristic length scale between sites @@ -356,10 +356,10 @@ function plot_spins!(ax, sys::System; notifier=Makie.Observable(nothing), arrows # Draw arrows linecolor = (stemcolor, alpha) - Makie.arrows!(ax, pts_shifted, vecs; arrowsize, linewidth, linecolor, arrowcolor, transparency=isghost) + Makie.arrows!(ax, pts_shifted, vecs; arrowsize, linewidth, linecolor, arrowcolor, diffuse=1.15, transparency=isghost) # Small sphere inside arrow to mark atom position - Makie.meshscatter!(ax, pts; markersize, color=linecolor, transparency=isghost) + Makie.meshscatter!(ax, pts; markersize, color=linecolor, diffuse=1.15, transparency=isghost) end if show_cell @@ -367,7 +367,7 @@ function plot_spins!(ax, sys::System; notifier=Makie.Observable(nothing), arrows # `overdraw=true` to work. pos = [(3/4)*Makie.Point3f0(p) for p in eachcol(orig_crystal(sys).latvecs)[1:dims]] text = [Makie.rich("a", Makie.subscript(repr(i))) for i in 1:dims] - Makie.text!(ax, pos; text, color=:black, fontsize=rescale*20, font=:bold, glowwidth=4.0, + Makie.text!(ax, pos; text, color=:black, fontsize=20, font=:bold, glowwidth=4.0, glowcolor=(:white, 0.6), align=(:center, :center), overdraw=true) end @@ -383,18 +383,19 @@ end An interactive crystal viewer, with bonds up to `max_dist`. """ function Sunny.view_crystal(cryst::Crystal, max_dist; show_axis=true, orthographic=false, - spherescale=0.2, resolution=(768, 512), rescale=1.0, dims=3) - fig = Makie.Figure(; resolution) + spherescale=0.2, size=(768, 512), dims=3) + fig = Makie.Figure(; size) ax = Makie.LScene(fig[1, 1], show_axis=false) # Show cell volume and label lattice vectors (this needs to come first to # set a scale for the scene in case there is only one atom). - Makie.linesegments!(ax, cell_wireframe(cryst.latvecs, dims); color=:teal, linewidth=rescale*1.5, inspectable=false) + Makie.linesegments!(ax, cell_wireframe(cryst.latvecs, dims); color=:teal, linewidth=1.5, inspectable=false) # Draw Cartesian axes axissize = (1/3)*minimum(norm.(eachcol(cryst.latvecs))) - axes = Makie.arrows!(ax, Makie.Point3f0.(fill([0,0,0], 3)), axissize*Makie.Point3f0.([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), - arrowsize=0.5axissize, linewidth=0.15axissize, color=[:red, :orange, :yellow], inspectable=false, visible=show_axis) + axisdirs = axissize * Makie.Point3f0.([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) + axes = Makie.arrows!(ax, Makie.Point3f0.(fill([0,0,0], 3)), axisdirs, arrowsize=0.5axissize, linewidth=0.15axissize, + color=[:red, :orange, :yellow], diffuse=1.15, inspectable=false, visible=show_axis) # Map atom classes to indices that run from 1..nclasses unique_classes = unique(cryst.classes) @@ -415,12 +416,12 @@ function Sunny.view_crystal(cryst::Crystal, max_dist; show_axis=true, orthograph push!(pts, cryst.latvecs * (cryst.positions[i] + n)) push!(color, getindex_cyclic(seaborn_muted, class_indices[i])) end - Makie.meshscatter!(ax, pts; markersize, color, alpha, inspectable=false, transparency=isghost) + Makie.meshscatter!(ax, pts; markersize, color, alpha, diffuse=1.15, inspectable=false, transparency=isghost) # Atom indices if !isghost text = repr.(eachindex(pts)) - atom_labels = Makie.text!(ax, pts; text, color=:white, fontsize=rescale*14, align=(:center, :center), + atom_labels = Makie.text!(ax, pts; text, color=:white, fontsize=16, align=(:center, :center), overdraw=true, visible=true) end end @@ -460,7 +461,7 @@ function Sunny.view_crystal(cryst::Crystal, max_dist; show_axis=true, orthograph # TODO: Report bug of ÷2 indexing inspector_label(plot, index, position) = bond_labels[index ÷ 2] - s = Makie.linesegments!(ax, segments; color, linewidth=rescale*3, + s = Makie.linesegments!(ax, segments; color, linewidth=3, inspectable=true, inspector_label, visible) return [s] end @@ -468,7 +469,7 @@ function Sunny.view_crystal(cryst::Crystal, max_dist; show_axis=true, orthograph layout = Makie.GridLayout(; tellheight=false, valign=:top) # Toggle on/off Cartesian axes - fontsize = rescale*16 + fontsize = 16 toggle_cnt = 0 axes_toggle = Makie.Toggle(fig; active=axes.visible[], buttoncolor=:gray) Makie.connect!(axes.visible, axes_toggle.active) @@ -505,7 +506,7 @@ function Sunny.view_crystal(cryst::Crystal, max_dist; show_axis=true, orthograph # v0.19) pos = [(3/4)*Makie.Point3f0(p) for p in eachcol(cryst.latvecs)[1:dims]] text = [Makie.rich("a", Makie.subscript(repr(i))) for i in 1:dims] - Makie.text!(ax, pos; text, color=:black, fontsize=rescale*20, font=:bold, glowwidth=4.0, + Makie.text!(ax, pos; text, color=:black, fontsize=20, font=:bold, glowwidth=4.0, glowcolor=(:white, 0.6), align=(:center, :center), overdraw=true) # Add inspector for pop-up information. Putting this last helps with @@ -548,7 +549,7 @@ function draw_level!(ax,n_level,level,center,radius,dir,z; arrows = true, linewi end end -function plot_coherents(sys::System{N};scale = 1., quantization_axis = nothing, use_arrows = true, resolution=(768, 512)) where N +function plot_coherents(sys::System{N};scale = 1., quantization_axis = nothing, use_arrows = true, size=(768, 512)) where N ℓ0 = characteristic_length_between_atoms(orig_crystal(sys)) @@ -564,7 +565,7 @@ function plot_coherents(sys::System{N};scale = 1., quantization_axis = nothing, n_level = length(sys.coherents[1]) - fig = Makie.Figure(; resolution) + fig = Makie.Figure(; size) ax = Makie.LScene(fig[1, 1]) # TODO: use `orient_camera!` at bottom of file instead.