MakieForProjectsModule

MakieForProjects.jl

MakieForProjects.jl has two purposes:

  1. Increase productivity when creating figures for (typically academic) papers or presentations within a self-contained project.
  2. Provide beautiful themes that maximize clarity. Different themes can be used for different projects and one can easily switch between light and dark background themes.

You are more than welcomed to use this to benefit from the themes, or the convenience functions within. Feel free to contribute PRs adding your own themes or more convenience functions.

Besides themeing, this package also provides several convenience functions for accelerating writing code for creating a figure in a (typically academic) project. Highlight is the axesgrid, figuretitle! and label_axes! functions. MakieForProjects.jl also integrates with DrWatson and overloads wsave for Makie.Figure objects.

For all other information, see the online docs.

source

Themeing

When using MakieForProjects, a default theme is applied that changes most theme aspects, and in particular the cycling of colors, markers, and lines. It makes fontsizes relatively larger (for the set figure size) which is typically desirable in both papers and presentations. To see all aspects that are changed see the source code of the MakieForProjects.make_theme function.

The color of the theme can be controlled in two ways. One, is by setting environment three environment variables before using the module:

# These are the default values
ENV["COLORSCHEME"] = "JuliaDynamics" # or others, see docs
ENV["BGCOLOR"] = :transparent        # anything for `backgroundcolor` of Makie
ENV["AXISCOLOR"] = :black            # color of all axis elements (labels, spines, ticks)

using MakieForProjects # this has now set the theme already!

# you may further edit the set theme by using
Makie.update_theme!(;
    # size = (figwidth, figheight),
)

The second way is to do

using MakieForProjects
theme = MakieForProjects.make_theme(colorcycle, bgcolor, axiscolor)
Makie.set_theme!(theme)

And make_theme can also be called without arguments, in which case it uses the same environmental parameters.

Themes

Themeing in MakieForProjects.jl aims to maximize clarity and aesthetics.

The color schemes in this repo are all composed of 6 colors. Max 6 because if you need more than 6 colors in your figure, you probably need to distinguish data with aspects other than color if you want clarity.

The color schemes have been created through extensive testing, so that their colors are most distinguishable with each other, visually aesthetic and thematic, are most distinguishable across all three major classes of color blindness, and are distinguishable also in greyscale (brightness).

Marker and linestyle cycles are added into themeing so that sequential scatter plots or line plots have different attributes that distinguish them beyond color.

The following constants are exported. The type CyclicContainer is a Vector-like that implements modulo indexing, wrapping around the indices after the length of the contained elements has been exhausted.

using MakieForProjects

COLORS
6-element MakieForProjects.CyclicContainer{String}:
 "#7143E0"
 "#191E44"
 "#0A9A84"
 "#AF9327"
 "#AB0E41"
 "#6C768C"
MARKERS
6-element MakieForProjects.CyclicContainer{Symbol}:
 :circle
 :dtriangle
 :rect
 :star5
 :xcross
 :diamond
LINESTYLES
5-element MakieForProjects.CyclicContainer{Any}:
 :solid
 :dash
 :dot
 Makie.Linestyle(Float32[0.0, 3.0, 4.0, 5.0, 6.0])
 Makie.Linestyle(Float32[0.0, 5.0, 6.0])

Available color schemes

using CairoMakie, MakieForProjects

testcolorscheme("JuliaDynamics")
Example block output
testcolorscheme("JuliaDynamicsLight")
Example block output
testcolorscheme("Petrol")
Example block output
testcolorscheme("CloudySky")
Example block output
testcolorscheme("Flames")
Example block output
testcolorscheme("GreenMetal")
Example block output
testcolorscheme("SandyBeach")
Example block output

Color manipulation

MakieForProjects.lightenFunction
lighten(c, f = 1.2)

Lighten given color c by multiplying its luminance with f. If f is less than 1, the color is darkened.

source
MakieForProjects.fadecolorFunction
fadecolor(c::ColorLike, N::Int, fade = 0.5)

Create a vector of N colors based on c but that "fade away" towards full transparency. The alpha channel (transparency) scales as t^fade with t ranging from 0 to 1 (1 being the end of the returned color vector). Use fade = 1 for linear fading or fade = 0 for no fading. Current default makes fading progress faster at start and slower towards the end.

Note: due to how makie handles transparency and different colors in a single line segment, if using fadecolor with lines! plots, it is best to also use the keywords:

linecap = :butt, joinstyle = :round
source

Convenience functions

Axes grid

MakieForProjects.axesgridFunction
axesgrid(m, n; kwargs...) -> fig, axs

Create a grid of m rows and n columns of axes in a new figure and return the figure and the Matrix of axis.

Keyword arguments

  • sharex/sharey = false: make every row share the y axis and/or every column share the x axis. In this case, tick labels are hidden from the shared axes.
  • titles::Vector{String}: if given, they are used as titles for the axes of the top row. Can also be a single String, in which case it is used for all axes.
  • xlabels::Vector{String}: if given, they are used as x labels of the axes in the bottom row. Can also be a single String, in which case it is used for all axes.
  • ylabels::Vector{String}: if given, they are used as y labels of the axes in the leftmost column. Can also be a single String, in which case it is used for all axes.
  • title::String: if given, it is used as super-title for the entire figure using the figuretitle! function.
  • xlims/ylims: if given, they set the limits of x/y for all axes.
  • kwargs...: all further keywords are propagated to Figure.
source
MakieForProjects.axesgrid!Function
axesgrid!(fig_loc, args...; kw...) -> axs

Do exactly the same with axesgrid(args...; kw...), but generate axes in a provided figure, or figure location, or grid layout from Makie.jl. E.g., fig = Figure(); fig_loc = fig[1,1].

source

Labelling functions

MakieForProjects.figuretitle!Function
figuretitle!(fig, title; kwargs...)

Add a title to a Figure, that looks the same as the title of an Axis by using the same default font. kwargs are propagated to Label.

source
MakieForProjects.label_axes!Function
label_axes!(axs::Iterable{Axis};
    valign = :top, halign = :right, pad = 4,
    transformation = x -> string(x),
    labels = range('a'; step = 1, length = length(axs)),
    add_box = false, boxkw = NamedTuple(), kw...
)

Add labels (like a,b,c,...) to all axes.

Keywords adjust location and padding and printing. All other keywords are propagated to either Label or textbox!, depending on whether add_box is true.

source
MakieForProjects.space_out_legend!Function
space_out_legend!(legend)

Space out the contents of a given legend, so that the banks are spaced equidistantly and cover the full width available for the legend. This function is supposed to be called for horizontal legends that should span the full width of a column and hence are placed either on top or below an axis.

source
MakieForProjects.textbox!Function
textbox!(ax::Axis, text::AbstractString; kw...)

Add a small textbox to ax containing the given text. This creates a Makie.Textbox at the same grid layout position as ax. By default, the textbox is placed at the top right corner with proper alignment. All keywords are propagated to Textbox.

source

Image file manipulation

Besides the functions below, MakieForProjects also overloads DrWatson._wsave, so that wsave works for Figure. By default it increments px_per_unit = 2 as well.

MakieForProjects.negate_remove_bgFunction
negate_remove_bg(file; threshold = 0.02, bg = :white, overwrite = false)

Create an negated (or color inverted) version of the image at file with background removed, so that it may be used in environments with dark background. The threshold decides when a pixel should be made transparent. If the image already has a dark background, pass bg = :black instead, which will not negate the image but still remove the background.

source
MakieForProjects.remove_bgFunction
remove_bg(file; threshold = 0.02, overwrite = false)

Remove the background for figure in file (all pixels with luminosity > 1 - threshold). Either overwrite original file or make a copy with suffix _bgr.

source