Skip to content

Utilities

addlabels!

Add labels to a provided grid layout, automatically searching for blocks to label.

julia
f = Foresight.demofigure()
addlabels!(f)
display(f)
CairoMakie.Screen{IMAGE}
Foresight.addlabels! Function
julia
addlabels!(gridpositions, f::Figure, [text]; dims=2, kwargs...)

Add labels to a provided grid layout. The labels are incremented in the linear order of the grid positions.

Arguments

  • gridpositions: An iterator of GridPositions as produced by e.g. subdivide.

  • f: The figure associated with the grid positions (optional)

  • text: Text to be displayed in the labels, as either an interator of strings or a function applied to the integer indices of the grid positions [optional; defaults to (a), (b), ...]

  • kwargs: Keyword arguments to be passed to the Label function.

Examples

julia
f = Figure()
gs = subdivide(f, 2, 2)
addlabels!(gs)
display(f)
source
julia
addlabels!(f::Figure, [text]; dims=2, allowedblocks = [Axis, Axis3, PolarAxis], recurse =
[GridContent, GridLayout], kwargs...)

Add labels to a provided grid layout, automatically searching for blocks to label.

Arguments

  • f: The figure to add labels to.

  • text: Text to be displayed in the labels, as either an interator of strings or a function applied to the integer indices of the grid positions [optional; defaults to (a), (b), ...]

  • dims: The dimension to increment labels; 1 for top-to-bottom increases (column major), or 2 for right-to-left increases (row-major; default).

  • allowedblocks: The types of blocks to consider for labelling (optional; defaults to [Axis, Axis3, PolarAxis]).

  • recurse: The types of blocks to recurse into for searching the allowedblocks (optional; defaults to [GridContent, GridLayout]).

  • kwargs: Keyword arguments to be passed to the Label function.

Examples

julia
f = Foresight.demofigure()
addlabels!(f)
display(f)

See also: addlabels!

source

seethrough

Converts a color gradient into a transparent version.

julia
C = cgrad(:viridis)
transparent_gradient = seethrough(C)

Foresight.seethrough Function
julia
seethrough(C::ContinuousColorGradient, start=0.0, stop=1.0)

Convert a color gradient into a transparent version

Examples

julia
C = sunrise;
transparent_gradient = seethrough(C)
source

scientific

Generate string representation of a number in scientific notation with a specified number of significant digits.

julia
scientific(1/123.456, 3) # "8.10 × 10⁻³"
"8.100 × 10⁻³"
Foresight.scientific Function
julia
scientific(x::Real, sigdigits=2)

Generate string representation of a number in scientific notation with a specified number of significant digits.

Arguments

  • x::Real: The number to be formatted.

  • sigdigits::Int=2: The number of significant digits to display.

Example

julia
scientific(1/123.456, 2) # "8.10 × 10⁻³"
source

There is also an lscientific method, which returns a LaTeX-style string:

julia
lscientific(1/123.456, 3)
"8.100\\times 10^{-3}"
Foresight.lscientific Function
julia
lscientific(x::Real, sigdigits=2)

Return a string representation of a number in scientific notation with a specified number of significant digits. This is not a LaTeXString. See Lscientific

Example

julia
x = lscientific(1/123.456, 2) # "8.10 \times 10^{-3}"
l = LaTeXString(x)
source

As well as Lscientific, which returns a LaTeXString:

julia
Lscientific(1/123.456, 3)

8.100\times 10^

Foresight.Lscientific Function
julia
lscientific(x::Real, sigdigits=2)

Return a string representation of a number in scientific notation with a specified number of significant digits, as a LaTeXString. See lscientific

Example

julia
x = Lscientific(1/123.456, 2) # L"8.10 \times 10^{-3}"
source

tick formatting

Format tick labels to be as compact as possible:

julia
lines(0:sqrt(2)/100:sqrt(2), sqrt; axis=(;xtickformat=terseticks))

Foresight.terseticks Function
julia
terseticks(x::Real; sigdigits=5, kwargs...)

Return a string representation of a number x with trailing zeros removed, rounded to the specified number of significant digits. The kwargs argument is passed to the round function.

source

Or, format proportion values as percentages:

julia
lines(0:0.01:1, sqrt; axis=(;xtickformat=percentageticks))

Foresight.percentageticks Function
julia
percentageticks(x)

Return an array of strings representing the values in x as percentages, rounded to the nearest integer.

source

reverse legend

Reverses the order of legend entries

Foresight.reverselegend! Function
julia
reverselegend!(l::Legend)

Reverse the order of the legend entries in an Axis object. This is useful when you want to change the order of the legend entries without changing the order of the plotted data.

source

brighten and darken

Brighten a color by a given factor by blending it with white:

julia
c = cornflowerblue
b = brighten(c, 0.2) # Brightens the color by 20%

Or, darken a color by blending it with black:

julia
c = cornflowerblue
d = darken(c, 0.2) # Darkens the color by 20%

widen

Slightly widens an interval by a fraction δ.

julia
x = 0..1
Foresight.widen(x, 0.1)
-0.1 .. 1.1
Foresight.widen Function

Slightly widen an interval by a fraction δ

source

freeze!

Freezes the axis limits of a Makie figure.

julia
fig, ax, plt = scatter(rand(10), rand(10))
freeze!(ax)

clip

Copies a Makie figure to the clipboard.

julia
fig, ax, plt = scatter(rand(10), rand(10))
clip(fig)
Foresight.clip Function
julia
tmpfile = clip(fig=Makie.current_figure(), fmt=:png; kwargs...)

Save the current figure to a temporary file and copy it to the clipboard. kwargs are passed to Makie.save.

Example

julia
f = plot(-5:0.01:5, x->sinc(x))
clip(f)
source

importall

Imports all symbols from a module into the current scope. Use with caution.

julia
importall(Foresight) .|> eval
Foresight.importall Function
julia
importall(module)

Return an array of expressions that can be used to import all names from a module.

Example

julia
importall(module) .|> eval
source