Skip to content

Commit

Permalink
configurable qplot defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosanjose committed Oct 21, 2023
1 parent 1613b41 commit 0d636c9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 47 deletions.
3 changes: 2 additions & 1 deletion ext/QuanticaMakieExt/QuanticaMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using Quantica: Lattice, LatticeSlice, AbstractHamiltonian, Hamiltonian,
argerror, harmonics, sublats, siterange, site, norm,
normalize, nsites, nzrange, rowvals, nonzeros, sanitize_SVector

import Quantica: plotlattice, plotlattice!, plotbands, plotbands!, qplot, qplot!
import Quantica: plotlattice, plotlattice!, plotbands, plotbands!, qplot, qplot!, qplotdefaults

# Currying fallback
Quantica.qplot(; kw...) = x -> Quantica.qplot(x; kw...)
Expand All @@ -18,6 +18,7 @@ Quantica.qplot!(; kw...) = x -> Quantica.qplot!(x; kw...)
include("plotlattice.jl")
include("plotbands.jl")
include("tools.jl")
include("defaults.jl")
include("docstrings.jl")

end # module
35 changes: 35 additions & 0 deletions ext/QuanticaMakieExt/defaults.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
############################################################################################
# qplot defaults
#region

function qplotdefaults(; figure = (;), axis = (;))
global default_figure_user = figure
global default_axis_user = axis
return (; default_figure_user, default_axis_user)
end

default_figure_user = (;)
default_axis_user = (;)

const plotlat_default_figure = (; resolution = (1200, 1200), fontsize = 40)

const plotlat_default_axis3D = (;
xlabel = "x", ylabel = "y", zlabel = "z",
xticklabelcolor = :gray, yticklabelcolor = :gray, zticklabelcolor = :gray,
xspinewidth = 0.2, yspinewidth = 0.2, zspinewidth = 0.2,
xlabelrotation = 0, ylabelrotation = 0, zlabelrotation = 0,
xticklabelsize = 30, yticklabelsize = 30, zticklabelsize = 30,
xlabelsize = 40, ylabelsize = 40, zlabelsize = 40,
xlabelfont = :italic, ylabelfont = :italic, zlabelfont = :italic,
perspectiveness = 0.0, aspect = :data)

const plotlat_default_axis2D = (; autolimitaspect = 1)

const plotlat_default_lscene = (;)

const plotlat_default_2D =
(plotlat_default_figure, plotlat_default_axis2D)
const plotlat_default_3D =
(plotlat_default_figure, plotlat_default_axis3D, plotlat_default_lscene)

#endregion
22 changes: 1 addition & 21 deletions ext/QuanticaMakieExt/plotbands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
const PlotBandsArgumentType =
Union{Quantica.Bandstructure,Quantica.Subband,AbstractVector{<:Quantica.Subband},AbstractVector{<:Quantica.Mesh},Quantica.Mesh}

function Quantica.qplot(b::PlotBandsArgumentType; fancyaxis = true, axis = (;), figure = (;), inspector = false, plotkw...)
function Quantica.qplot(b::PlotBandsArgumentType; fancyaxis = true, axis = default_axis_user, figure = default_figure_user, inspector = false, plotkw...)
meshes = collect(Quantica.meshes(b))
E = Quantica.embdim(first(meshes))
fig, ax = if E < 3
Expand All @@ -43,26 +43,6 @@ end

Quantica.qplot!(b::PlotBandsArgumentType; kw...) = plotbands!(b; kw...)

const plotbands_default_figure = (; resolution = (1200, 1200), fontsize = 40)

const plotbands_default_axis3D = (;
xticklabelcolor = :gray, yticklabelcolor = :gray, zticklabelcolor = :gray,
xspinewidth = 0.2, yspinewidth = 0.2, zspinewidth = 0.2,
xlabelrotation = 0, ylabelrotation = 0, zlabelrotation = 0,
xticklabelsize = 30, yticklabelsize = 30, zticklabelsize = 30,
xlabelsize = 40, ylabelsize = 40, zlabelsize = 40,
xlabelfont = :italic, ylabelfont = :italic, zlabelfont = :italic,
perspectiveness = 0.0, aspect = :data)

const plotbands_default_axis2D = (; autolimitaspect = nothing)

const plotbands_default_lscene = (;)

const plotbands_default_2D =
(plotbands_default_figure, plotbands_default_axis2D)
const plotbands_default_3D =
(plotbands_default_figure, plotbands_default_axis3D, plotbands_default_lscene)

#endregion

############################################################################################
Expand Down
27 changes: 3 additions & 24 deletions ext/QuanticaMakieExt/plotlattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ end

const PlotLatticeArgumentType{E} = Union{Lattice{<:Any,E},LatticeSlice{<:Any,E},AbstractHamiltonian{<:Any,E}}

function Quantica.qplot(h::PlotLatticeArgumentType{3}; fancyaxis = true, axis = (;), figure = (;), inspector = false, plotkw...)
function Quantica.qplot(h::PlotLatticeArgumentType{3}; fancyaxis = true, axis = default_axis_user, figure = default_figure_user, inspector = false, plotkw...)
fig, ax = empty_fig_axis_3D(plotlat_default_3D...; fancyaxis, axis, figure)
plotlattice!(ax, h; plotkw...)
inspector && DataInspector()
return fig
end

function Quantica.qplot(h::PlotLatticeArgumentType; axis = (;), figure = (;), inspector = false, plotkw...)
function Quantica.qplot(h::PlotLatticeArgumentType; axis = default_axis_user, figure = default_figure_user, inspector = false, plotkw...)
fig, ax = empty_fig_axis_2D(plotlat_default_2D...; axis, figure)
plotlattice!(ax, h; plotkw...)
inspector && DataInspector()
return fig
end

function Quantica.qplot(g::GreenFunction; fancyaxis = true, axis = (;), figure = (;), inspector = false, children = missing, plotkw...)
function Quantica.qplot(g::GreenFunction; fancyaxis = true, axis = default_axis_user, figure = default_figure_user, inspector = false, children = missing, plotkw...)
fig, ax = empty_fig_axis(g; fancyaxis, axis, figure)
Σkws = Iterators.cycle(parse_children(children))
Σs = Quantica.selfenergies(Quantica.contacts(g))
Expand Down Expand Up @@ -81,27 +81,6 @@ empty_fig_axis(::GreenFunction{<:Any,3}; kw...) =
empty_fig_axis(::GreenFunction; kw...) =
empty_fig_axis_2D(plotlat_default_2D...; kw...)

const plotlat_default_figure = (; resolution = (1200, 1200), fontsize = 40)

const plotlat_default_axis3D = (;
xlabel = "x", ylabel = "y", zlabel = "z",
xticklabelcolor = :gray, yticklabelcolor = :gray, zticklabelcolor = :gray,
xspinewidth = 0.2, yspinewidth = 0.2, zspinewidth = 0.2,
xlabelrotation = 0, ylabelrotation = 0, zlabelrotation = 0,
xticklabelsize = 30, yticklabelsize = 30, zticklabelsize = 30,
xlabelsize = 40, ylabelsize = 40, zlabelsize = 40,
xlabelfont = :italic, ylabelfont = :italic, zlabelfont = :italic,
perspectiveness = 0.0, aspect = :data)

const plotlat_default_axis2D = (; autolimitaspect = 1)

const plotlat_default_lscene = (;)

const plotlat_default_2D =
(plotlat_default_figure, plotlat_default_axis2D)
const plotlat_default_3D =
(plotlat_default_figure, plotlat_default_axis3D, plotlat_default_lscene)

#endregion

############################################################################################
Expand Down
3 changes: 2 additions & 1 deletion src/Quantica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export sublat, bravais_matrix, lattice, sites, supercell,
unflat, wrap, transform, translate, combine,
spectrum, energies, states, bands, subdiv,
greenfunction, selfenergy, attach, contact, cellsites,
plotlattice, plotlattice!, plotbands, plotbands!, qplot, qplot!,
plotlattice, plotlattice!, plotbands, plotbands!, qplot, qplot!, qplotdefaults,
conductance, josephson, ldos, current, transmission

export LatticePresets, LP, RegionPresets, RP, HamiltonianPresets, HP
Expand Down Expand Up @@ -84,6 +84,7 @@ function plotbands end
function plotbands! end
function qplot end
function qplot! end
function qplotdefaults end

qplot(args...; kw...) =
argerror("No plotting backend found or unexpected argument. Forgot to do e.g. `using GLMakie`?")
Expand Down

0 comments on commit 0d636c9

Please sign in to comment.