Public Documentation
Documentation for MakieMaestro.jl
's public interface.
Contents
Exporting
MakieMaestro.savefig
— Functionsavefig(fig, [path], [size]; <keyword arguments>)
Save the figure fig
at path
with size
.
Themes are applied from the :base
theme and you can supply any number of overrides, either predefined or you own.
The arguments fig
, path
and size
may be specified in a number of different ways as shown below in Arguments or in the case of path
and size
be left with their default values (see Themes.width!
, Themes.hwratio!
, figure_dir!
and export_format!
). For a clearer picture of how to supply the arguments, see Examples in the documentation, but as a rule of thumb, any sensible way to define the export arguments should work granted that they are in the correct order.
If PdfTex
format is requested, Inkscape
is used to convert the SVG
file to PDF
with text in LaTeX.
Arguments
fig
– figure(s) generating function
fig_func::Function, (arg1, arg2,...)
, () -> fig_func(arg1, arg2,...)
or fig_func
(if it is possible to call it without any arguments). This is the only argument that is necessary to provide. See FunctionSpec
.
path
: basename, directory and formats
name, [formats], [dir]
or path
. In example "protein_density_heatmap", [:svg, :pdf, :pdf_tex], "~/ImporantProject/"
or equivalently "~/ImporantProject/protein_density_heatmap.{svg, pdf, pdf_tex}"
. If not supplied, the name is inferred from nameof(fig_func)
, formats
are taken from MakieMaestro.get_export_format
(see also export_format!
) and dir
is taken from MakieMaestro.get_figure_dir
(see also figure_dir!
). See PathSpec
.
size
: physical dimensions of the figure (determining combination of width, height and hwratio)
20.5u"cm", 0.6
, FigHeight(5u"inch"), 8u"inch"
, 0.5, 1.5
(relative width, hwratio), HeightLength(0.3), 0.4
(relative height, hwratio). The defaults can be set by width!
and hwratio!
. See SizeSpec
.
Keyword arguments
backends=CairoMakie
override_theme=Theme()
[update]
(default: determine by the backend)- Any additional keyword arguments are supplied to the figure function
MakieMaestro.figure_dir!
— Functionfigure_dir!(dir)
Set the figure directory
Examples
julia> figure_dir!(".");
MakieMaestro.export_format!
— Functionexport_format!(formats)
Set the default formats to export.
julia> export_format!(["pdf", :eps]);
julia> export_format!("pdf", MakieMaestro.Png, :svg);
julia> export_format!(missing);
Internals
MakieMaestro.isvectorgraphic
— FunctionMakieMaestro.isvectorgraphic(x::Format)
Return true
if x
is a vector graphic format, false
otherwise.
Examples
julia> MakieMaestro.isvectorgraphic(MakieMaestro.Pdf)
true
julia> MakieMaestro.isvectorgraphic(MakieMaestro.Png)
false
MakieMaestro.skip
— FunctionMakieMaestro.skip(skips::Vararg{Union{Symbol,Format}})
Return a Set{Format}
of allowed formats by excluding specified formats or format groups.
Useful for customizing the output formats when saving figures, allowing you to easily exclude certain format types or groups of formats.
Arguments
skips
: Variable number of arguments specifying formats or format groups to exclude. Can be individualFormat
types or symbols:raster
or:vector
.
Examples
julia> @assert MakieMaestro.skip(:raster) == Set([MakieMaestro.PdfTex, MakieMaestro.Eps, MakieMaestro.Svg, MakieMaestro.Pdf])
julia> @assert MakieMaestro.skip(:vector) == Set([MakieMaestro.Png])
julia> @assert MakieMaestro.skip(MakieMaestro.Pdf, MakieMaestro.Svg) == Set([MakieMaestro.PdfTex, MakieMaestro.Png, MakieMaestro.Eps])
MakieMaestro.extension
— FunctionMakieMaestro.extension(format::Format)
Return the string of the extension from the given format
.
Examples
julia> MakieMaestro.extension(MakieMaestro.Png)
".png"
julia> MakieMaestro.extension(MakieMaestro.PdfTex)
".pdf"
MakieMaestro.choose_backend
— FunctionMakieMaestro.choose_backend(backends::Vector{Module}, f::Format)
Select the best backend from backends
to export a figure in the format f
.
Prefers CairoMakie
for most formats unless the format is Png
and GLMakie
is available.
Examples
julia> MakieMaestro.choose_backend([CairoMakie, GLMakie], MakieMaestro.Svg)
CairoMakie
julia> MakieMaestro.choose_backend([WGLMakie], MakieMaestro.Eps)
ERROR: None of the backends support the format Eps
[...]
MakieMaestro.backend_formats
— FunctionMakieMaestro.backend_formats(backend::Module,...)
Return the set of compatible formats for given backend
s.
Examples
julia> @assert Set([ MakieMaestro.Png, MakieMaestro.Eps, MakieMaestro.Svg, MakieMaestro.Pdf ]) ⊆ MakieMaestro.backend_formats(CairoMakie)
julia> @assert MakieMaestro.backend_formats(GLMakie) == Set([MakieMaestro.Png])
MakieMaestro.get_figure_dir
— FunctionMakieMaestro.get_figure_dir()
Get the figure directory
Examples
julia> figure_dir!("/tmp")
"/tmp"
julia> MakieMaestro.get_figure_dir()
"/tmp"
MakieMaestro.get_themes
— FunctionMakieMaestro.get_themes(backend::Module, format::Format)
Get the modification themes associated with the backend
and format
.
Examples
julia> MakieMaestro.get_themes(CairoMakie, MakieMaestro.PdfTex)
2-element Vector{Symbol}:
:cairomakie
:vector
julia> MakieMaestro.get_themes(GLMakie, MakieMaestro.Png)
2-element Vector{Symbol}:
:glmakie
:raster
MakieMaestro.get_export_theme
— FunctionMakieMaestro.get_export_theme(backend, format, width, hwratio, override_theme...)
Create the final export theme applied when generating the figure.
Examples
julia> MakieMaestro.get_export_theme(CairoMakie, MakieMaestro.Png, 10u"cm", 0.8,
Theme(;
CairoMakie=(;pdf_version=1.1)
),
Theme(;
Scatter=(;markersize=8)
)
)
Attributes with 12 entries:
Axis => Attributes with 8 entries:
xgridvisible => false
xticklabelsize => 10
xticksize => 4
xtickwidth => 0.7
ygridvisible => false
yticklabelsize => 10
yticksize => 4
ytickwidth => 0.7
backgroundcolor => transparent
CairoMakie => Attributes with 1 entry:
pdf_version => 1.1
Colorbar => Attributes with 9 entries:
bottomspinevisible => false
labelsize => 10
leftspinevisible => false
rightspinevisible => false
ticklabelsize => 10
ticksize => 4
tickwidth => 0.7
topspinevisible => false
width => 5
figure_padding => 2
fonts => Attributes with 4 entries:
bold => FTFont (family = NewComputerModern, style = 10 Bold)
bolditalic => FTFont (family = NewComputerModern, style = 10 Bold Italic)
italic => FTFont (family = NewComputerModern, style = 10 Italic)
regular => FTFont (family = NewComputerModern Math, style = Regular)
Heatmap => Attributes with 1 entry:
colormap => Spectral
Image => Attributes with 1 entry:
interpolate => false
Legend => Attributes with 5 entries:
framevisible => false
labelsize => 10
nbanks => 1
tellheight => false
tellwidth => false
Lines => Attributes with 1 entry:
cycle => Cycle([[:color]=>:color, [:marker]=>:marker], true)
Scatter => Attributes with 3 entries:
cycle => Cycle([[:color]=>:color, [:marker]=>:marker], true)
markersize => 8
strokewidth => 0
size => (283, 226)
MakieMaestro.get_formats
— FunctionMakieMaestro.get_formats(backends::Vector{Module}, formats::Set{Format})
Return the list (Vector
) of formats to generate based on the given backends
required formats
. Output is in the correct order for export.
Examples
julia> (Sys.which("inkscape") === nothing) || MakieMaestro.Svg ∈ MakieMaestro.get_formats([CairoMakie], Set([MakieMaestro.PdfTex])) # Added Svg so the PdfTex is possible to create
true
julia> MakieMaestro.get_formats([GLMakie], Set([MakieMaestro.Pdf]))
ERROR: ArgumentError: None of the backends Module[GLMakie] support the formats Set(MakieMaestro.Format[MakieMaestro.Pdf])
[...]
julia> MakieMaestro.get_formats([CairoMakie, GLMakie], Set([MakieMaestro.Png, MakieMaestro.Svg]))
2-element Vector{MakieMaestro.Format}:
Svg::Format = 1
Png::Format = 0
MakieMaestro.FunctionSpec
— TypeFunctionSpec(fig, args)
Specification of the function generating the figure with its arguments.
Can be called with additional keyword arguments. The arguments are passed from the args
field.
MakieMaestro.PathSpec
— TypePathSpec(basename, [formats], [dirname])
PathSpec(fullpath, [formats])
Specification of where and which format to use for exporting a figure.
basename
is internally a function that takes an index integer and returns the name of the figure. The function is created either by a suffix or by parsing the supplied string (see examples below).formats
is a set or collection of formats wanted for the export.dirname
is the directory where the figure will be saved (checked for existence upon creation).
Examples
```jldoctest; setup=:(using MakieMaestro: PathSpec) julia> PathSpec("somefile.pdf", ".") ./somefile.pdf
julia> PathSpec("somefile.{svg,eps}", "..") ../somefile.{eps,svg}
julia> PathSpec("somefile.png", "nonexistentdir") ERROR: ArgumentError: `nonexistent_dir` is not a valid directory [...]
julia> PathSpec("somefile",["pdf", :svg], "..") ../somefile.{pdf,svg}```
MakieMaestro.get_export_format
— FunctionMakieMaestro.get_export_format()
Get the default export formats
Examples
julia> export_format!(:pdf)
Set{MakieMaestro.Format} with 1 element:
MakieMaestro.Pdf
julia> MakieMaestro.get_export_format()
Set{MakieMaestro.Format} with 1 element:
MakieMaestro.Pdf
julia> export_format!(missing);
MakieMaestro.SizeSpec
— TypeMakieMaestro.SizeSpec(width::Length, hwratio::Real)
Specification of the physical size of the exported image.
The primary way to represent the size of a figure is it's width
and the height to width ratio hwratio
. However, any set of two values from {width
, hwratio
, height
} fully determine the size. width
and height
may be either fixed values of the type Length
or relative sizes to their default values by the type Real
(RelativeSize
). None, one or two of the values may be supplied and the size is determined from these values and the defaults. These defaults may be set with width!
and hwratio!
.
See also Themes.width!
, Themes.get_width
, Themes.hwratio!
, Themes.get_hwratio
Examples
julia> Themes.width!(Themes.A4_WIDTH), Themes.hwratio!(2/(√(5) + 1));
julia> SizeSpec(0.5, 2)
w×h: 105.0 mm × 210.0 mm [h/w: 2.0]
julia> SizeSpec(10u"cm")
w×h: 10.0 cm × 6.18 cm [h/w: 2/(√5 + 1)]
julia> SizeSpec((15u"cm", 10u"cm"))
w×h: 10.0 cm × 15.0 cm [h/w: 1.5]
julia> SizeSpec((15u"cm", 0.5))
w×h: 105.0 mm × 150.0 mm [h/w: 1.4]
julia> SizeSpec((2, 10u"cm"))
w×h: 10.0 cm × 12.36 cm [h/w: 1.2]
MakieMaestro.RelativeSize
— TypeMakieMaestro.RelativeSize(ratio::Real)
Size relative to the default or calculated dimensions.
MakieMaestro.FigHeight
— TypeFigHeight(height::Length)
FigHeight(height::Real) # relative size to the default
Specifies the height of the exported figure.
See also RelativeSize
.
MakieMaestro._savefig
— Function_savefig(fig, name, format, backend, dir; update)
Save figure fig
with backend
and name
in dir
with format
.
Internal function that gets called at the end of the saving stack with all of the arguments already fully determined and the figure created with the theme activated. update
should be true
if the Axis
is created separately from the plot inside in order to set the correct viewing limits for the figure.
MakieMaestro._savepdftex
— Function_savepdftex(svgpath, outputpath; wait=true)
Run the command for creating a PDFTEX
figure using Inkscape.
Internal function to convert SVG
figures to PDFTEX
(PDF
+LaTeX
) format assuming that the SVG
already exists. If wait
then the command in ran as blocking.
Documenter
MakieMaestro.docblocks
— Functiondocblocks(path=@__DIR__ * "assets/figs/", formats=[:svg, :pdf])
Create the plugin for generating Documenter figures from blocks of code in the documentation pages.
Theming
MakieMaestro.Themes
— ModuleThis module is used to set themes for your figures. It can help you define a consistent theming scheme for your saved figures and for the figures you experiment with interactively.
It intends to solve the problem, where Makie
gives you the option of theming, but if you want to change the theme at multiple places with multiple attribute changes and perhaps combine these options differently for your figures, it is necessary that you create the override themes and merge them with the current one which sooner or later becomes tedious and error prone. Especially if you are to create a lot of figures with various theming preferences. This tries to make theming and keeping consistency in your plots a little bit easier by allowing you to define all the connected attributes in one theme, register it with update_theme!(:my_theme, theme)
and use these where necessary in your figure creation process and when saving.
MakieMaestro.Themes.width!
— Functionwidth!(val::Length)
Set the default width for figures.
julia> width!(177u"mm" * 0.8)
141.6 mm
julia> Themes.get_width()
141.6 mm
MakieMaestro.Themes.hwratio!
— Functionhwratio!(val)
Set the height-width ratio for saving figures.
julia> hwratio!((1 + √(5))/2)
1.618033988749895
julia> Themes.get_hwratio()
1.618033988749895
MakieMaestro.Themes.update_theme
— Functionupdate_theme(key::Symbol, with::ThemeGenerator)
Update a specific theme component identified by key
in the global THEME
dictionary.
Arguments
key::Symbol
: The key identifying the theme component to update.with::ThemeGenerator
: The new theme or function to update the existing theme with.
See also update_theme!
for direct modifications.
Extended help
Specific behaviour for argument types:
- If the
key
doesn't exist inTHEME
, it adds the new theme or function. - If the
key
exists:- For an existing
Theme
:- If
with
is aFunction
, it merges the result ofwith
with the current theme. - If
with
is aTheme
, it merges the current theme withwith
.
- If
- For an existing
Function
:- If
with
is aTheme
, it creates a new function that mergeswith
with the result of the current function. - If
with
is aFunction
, it throws anArgumentError
.
- If
- For an existing
Throws
ArgumentError
: If attempting to update a generating function with another generating
function.
MakieMaestro.Themes.update_theme!
— Functionupdate_theme!(key::Symbol, new::ThemeGenerator)
Update a specific theme component in the global theme.
Arguments
key::Symbol
: The key representing the theme component to be updated.new::ThemeGenerator
: The new theme generator to replace the existing one.
This function modifies the global theme by replacing the theme generator for the specified component with a new one. It directly updates the THEME
global variable.
See also update_theme
MakieMaestro.Themes.get_theme
— Functionget_theme(themes::Vector{Union{ThemeGenerator,Symbol}}; dict = THEME[])
get_theme(A, B, C, ...; dict = THEME[])
Create theme for specified keys and/or generators (including Theme
s).
Later arguments have precedence similarly to Base.merge(A::Dict, B::Dict)
.
Arguments
keys
: AVector
orVararg
of symbols, functions generating themes or themes. Symbols are taken as keys from the dict.
Examples
julia> gap = true
true
julia> theme_props = MakieMaestro.Themes.get_theme([Theme(; figure_padding=2), () -> Theme(; colgap = gap, rowgap = gap), :orange_title])
Attributes with 4 entries:
Axis => Attributes with 1 entry:
titlecolor => orange
colgap => true
figure_padding => 2
rowgap => true
MakieMaestro.Themes.theme_keys
— Functiontheme_keys()
Show the that are defined in the theme dictionary.
julia> theme_keys()[1:3]
3-element Vector{Symbol}:
:base
:cairomakie
:data_aspect
Internals
MakieMaestro.Themes.ThemeGenerator
— TypeThemeGenerator == Union{Function,Theme}
A struct used for defining new theme “mixins” that can be inferred from some latent parameters.
That the function returns a Theme
value is not checked. Therefore this type is only to be used internally...
julia> (() -> nothing) isa MakieMaestro.Themes.ThemeGenerator
true
MakieMaestro.Themes.gen
— Functiongen(s::Symbol; dict=THEME[])
Return the function from the key s
of dict.
MakieMaestro.Themes.merge_generate
— Functionmerge_generate(theme::ThemeGenerator,...)::Theme
Generate and merge all the theme
arguments.
Later input arguments have precedence similarly as in a merge of dictionaries.
See also get_theme
, ThemeGenerator
Examples
julia> MakieMaestro.Themes.merge_generate(Theme(; figure_padding=3), () -> Theme(; figure_padding=6))
Attributes with 1 entry:
figure_padding => 6
MakieMaestro.Themes.get_hwratio
— FunctionThemes.get_hwratio()
Get the set height-width ratio for saving figures.
Examples
julia> hwratio!(0.5)
0.5
julia> Themes.get_hwratio()
0.5
MakieMaestro.Themes.get_width
— FunctionThemes.get_width()
Get the default figure width
Examples
julia> width!(10u"cm")
10 cm
julia> Themes.get_width()
10 cm
MakieMaestro.Themes.to_units
— FunctionThemes.to_units(val::Length)
Convert val
to Makie figure units
Example
julia> Themes.to_units(2u"cm")
7200//127
MakieMaestro.Themes.figsize
— Functionfigsize(width::Length=get_width(), hw_ratio=get_hwratio())
Calculate the figure size in points (1u"pt" == (1//72)u"inch"
) based on the given width and height-to-width ratio.
Examples
julia> w,h = Themes.figsize(32u"cm", (1 + √(5))/2)
(907, 1467)
MakieMaestro.Themes.ScreenInfo
— TypeMakieMaestro.Themes.ScreenInfo
Fields
default::Union{Missing,Bool}
– X11 default screenindex::Int
– X11 screen indexsize::Tuple{Int,Int}
– pixel dimensions of the displaydimensions::Tuple{Length,Length}
– physical dimensions of the display
MakieMaestro.Themes.interactive_size!
— Functioninteractive_size!(size::Tuple{Length,Length})
interactive_size!(ratio::Tuple{Number,Number}; index=nothing)
Set the interactive figure size.
If given a ratio
, calculate the size from the screen parameters so that the figure takes up the given width/height ratio of the screen. The optional index specifies the screen to use.
See also screen_parameters
, get_interactive_size
MakieMaestro.Themes.get_interactive_size
— Functionget_interactive_size()
Retrieve the current interactive size setting for figures.
This function checks the global INTERACTIVE_SIZE
variable and returns its value. If INTERACTIVE_SIZE
is not set (i.e., it's missing
), it attempts to set a default size of 80% of the screen dimensions using interactive_size!((0.8, 0.8))
.
See also interactive_size!
Throws
ErrorException
: IfINTERACTIVE_SIZE
is not set and the function fails to set a default value.
MakieMaestro.Themes.screen_parameters
— Functionscreen_parameters()
Retrieve information about available screens (Vector{ScreenInfo}
) using the xdpyinfo
command.
This function parses the output of xdpyinfo
to extract details about each screen, including its index, dimensions in pixels and millimeters, and whether it's the default screen.
Examples
screens = screen_parameters()
for screen in screens
println("Screen $(screen.index): $(screen.size) pixels, $(screen.dimensions) physical size")
end
# Screen 0: (4080, 1920) pixels, (1072 mm, 504 mm) physical size
See also ScreenInfo
Extended help
- This function relies on the
xdpyinfo
command and is therefore only compatible with systems where this command is available (typically Unix-like systems with X11). - The function may return an empty vector if no screens are detected or if parsing fails.
- Requires the Unitful.jl package for handling millimeter units.
Plotting
Overrides
MakieMaestro.Recipes.image!
— FunctionRecipes.image!(args...; decorations=false, interpolate=false, axis=(; aspect=DataAspect()), colormap=:viridis, kwargs...)
Modified image!
recipe that enables the user to set axis
attributes even with the mutating function and has different defaults.
decorations
– hide the axis decorations if set tofalse
MakieMaestro.Recipes.image
— FunctionRecipes.image(f)
Helper for setting the prefered options (interpolate
, ax.aspect
, decorations) for the image recipe.
Plotting functions
MakieMaestro.Recipes.mosaic
— Functionmosaic(datas::AbstractVector;
nrows, ncols,
plt=Recipes.image!, ax_func! = identity, linkaxes=true, vargs...)
mosaic(datas::Stack, args...; vargs...)
mosaic(datas::AbstractMatrix; vargs...)
Create a grid-like arrangement of plots.
Arguments
datas
: Vector, 3D array, or matrix of data to be plottednrows
/ncols
: Number of rows / columnsplt
: Plotting function to apply (default:image!
)ax!
: Function to modify axis properties (default: identity)linkaxes
: Boolean to control axis linking (default: true)vargs...
: Additional plotting arguments passed to the plotting function
The function creates a Makie Figure object with a grid of plots, applies the specified plotting function to each data element, and returns the resulting figure. It supports vectorized arguments that match the data length and automatically handles tuple-packed data.
Returns
- A Makie Figure object containing the mosaic of plots that have linked axes
Examples
# Basic usage with vector of matrices
data = [rand(10,10) for i in 1:4]
fig = mosaic(data, 2, 2)
# Using with a 3D array
data3d = rand(10,10,4)
fig = mosaic(data3d)
# Using with a matrix
datamat = [rand(2,3) for _ in 1:3, _ in 1:4]
fig = mosaic(datamat)
Utility / QOL functions
MakieMaestro.L
— FunctionL(s::String)
Shortcut for latexstring(raw" ext{" * s * "}")
.
This is useful when you want to have LaTeX axis labels, but do not want to use the theme_latexfonts()
theme.
MakieMaestro.fftvis
— Functionfftvis(fft_img)
Apply a logarithmic scaling to visualize the absolute value of the Fourier image.
Extended help
This function takes the absolute value of the input img
(typically the result of an FFT), adds 1 to avoid log(0), and then applies a base-2 logarithm. This scaling helps to visualize the wide dynamic range typically present in Fourier transforms of images.
Examples
using FFTW
img = rand(100, 100)
fft_img = fft(img)
heatmap(fftvis(fftshift(fft_img)))