Skip to content

Commit

Permalink
Merge pull request #220 from pablosanjose/qplotdefaults
Browse files Browse the repository at this point in the history
Configurable qplot defaults
  • Loading branch information
pablosanjose authored Oct 21, 2023
2 parents 8c866df + a487573 commit caac64e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 47 deletions.
3 changes: 3 additions & 0 deletions docs/src/tutorial/lattices.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ julia> qplot(lat, hide = nothing)
!!! tip "GLMakie.jl vs CairoMakie.jl"
GLMakie.jl is optimized for interactive GPU-accelerated, rasterized plots. If you need to export to PDF for publications or display plots inside a Jupyter notebook, use CairoMakie.jl instead, which in general renders non-interactive, but vector-based plots.

!!! tip "User-defined defaults for `qplot`"
The command `qplotdefaults(; axis, figure)` can be used to define the default value of `figure` and `axis` keyword arguments of `qplot`. Example: to fix the resolution of all subsequent plots, do `qplotdefaults(; figure = (resolution = (1000, 1000),))`.

## [SiteSelectors](@id siteselectors)

A central concept in Quantica.jl is that of a "selector". There are two types of selectors, `SiteSelector`s and `HopSelectors`. `SiteSelector`s are a set of directives or rules that define a subset of its sites. `SiteSelector` rules are defined through three keywords:
Expand Down
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
61 changes: 61 additions & 0 deletions ext/QuanticaMakieExt/defaults.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
############################################################################################
# qplot defaults
#region

## qplot defaults

function qplotdefaults(; figure = (;), axis = (;))
global default_figure_kwarg = figure
global default_axis_kwarg = axis
return (; default_figure_kwarg, default_axis_kwarg)
end

default_figure_kwarg = (;)
default_axis_kwarg = (;)

## plotlattice defaults

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)

## plotbands defaults

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
18 changes: 18 additions & 0 deletions ext/QuanticaMakieExt/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ cycling over them if necessary.
- `inspector::Bool`: whether to enable interactive tooltips of plot elements
- `plotkw`: additional keywords to pass on to `plotlattice` or `plotbands`, see their docstring for details.
# See also
`plotlattice`, `plotbands`, `qplotdefaults`
"""
qplot

Expand Down Expand Up @@ -137,3 +139,19 @@ Render bands-based `object` on currently active scene. See `plotbands` for possi
"""
plotbands!

"""
qplotdefaults(; figure = (;), axis = (;))
Define default values for the `figure` and `axis` keyword arguments of `qplot`.
# Examples
```jldoctest
julia> qplotdefaults(figure = (resolution = (1000, 1000),))
(default_figure_kwarg = (resolution = (1000, 1000),), default_axis_kwarg = NamedTuple())
julia> qplotdefaults()
(default_figure_kwarg = NamedTuple(), default_axis_kwarg = NamedTuple())
```
"""
qplotdefaults
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_kwarg, figure = default_figure_kwarg, 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_kwarg, figure = default_figure_kwarg, 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_kwarg, figure = default_figure_kwarg, 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_kwarg, figure = default_figure_kwarg, 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 caac64e

Please sign in to comment.