SpacePhysicsMakie.jl

DOI version

SpacePhysicsMakie.jl provides a set of utilities for visualizing space physics data:

  • tplot_panel: Creates single panel plots with support for multiple data types
  • tplot: Combines multiple panels into a figure

tplot_panel handles various time series formats including vectors, matrices, functions. It renders data as line plots, series plots, spectrograms and overlaid plots.

tplot offers flexible visualization options, allowing you to display multiple time series either across separate panels.

SpacePhysicsMakie integrates with many packages in the space physics ecosystem through a common API defined in SpaceDataModel.jl. See real world example of using Speasy.jl to retrieve and visualize data. More demos are available in the Examples page.

Built on Makie's complex layouts capabilities, tplot provides both interactive exploration capabilities and publication-quality output. It features dynamic data loading during zoom/pan operations, efficiently retrieving and rendering data on demand.

SpacePhysicsMakie.tplotFunction
tplot(f, tas; legend=(; position=Right()), link_xaxes=true, link_yaxes=false, rowgap=5, kwargs...)

Lay out multiple time series across different panels (rows) on one Figure / GridPosition f

If legend is nothing, no legend will be added to the plot. Otherwise, legend can be a NamedTuple containing options for legend placement and styling. By default, the time series are transformed via extensible transform.

See also: tplot_panel, transform

source
SpacePhysicsMakie.tplot_panelFunction
tplot_panel(gp, args...; kwargs...)

Generic entry point for plotting different types of data on a grid position gp.

Transforms the arguments to appropriate types and calls the plotting function. Dispatches to appropriate implementation based on the plotting trait of the transformed arguments.

source
SpacePhysicsMakie.tplot_panel!Function
tplot_panel!(ax, args...; kwargs...)

Generic entry point for adding plots to an existing axis ax.

Transforms the arguments to appropriate types and calls the plotting function. Dispatches to appropriate implementation based on the plotting trait of the transformed arguments.

source

Installation

using Pkg
Pkg.add("SpacePhysicsMakie")

Flexible tplot_panel

using Unitful
using CairoMakie, SpacePhysicsMakie

# Create sample data
n = 24
data1 = rand(n) * 4u"km/s"  # Vector with units
data2 = rand(n) * 4u"km/s"  # Same units
data3 = rand(n) * 1u"eV"    # Different units
data4 = rand(n,4)           # Matrix (for heatmap)

f = Figure()

# Basic Plotting
tplot_panel(f[1, 1], data1; axis=(;title="Single time series"))

# Multiple Series (same y-axis)
tplot_panel(f[2, 1], [data1, data2]; axis=(;title="Multiple series"), plottypes=Lines)

# Secondary Y-Axes for different units with different plot types
tplot_panel(f[3, 1], (data1, data3); axis=(;title="Secondary y-axes"), plottypes=(Lines, ScatterLines))

# Combine with plain `Makie` plots to plot matrix as `series`
series(f[1, 2], data4'; axis=(;title="Series"))

# Overlay Series on Heatmap
tplot_panel(f[2, 2], [data4, data1, data2]; axis=(;title="Heatmap with overlays"))

# XY Plot (non-time series)
tplot_panel(f[3, 2], sort(data2), data3; axis=(;title="XY plot (fallback)"))

f
Example block output

Composable tplot

You can also combine multiple panels into a single figure using tplot. By default, it links the x-axis of each panel and layouts the panels in a single column.

tvars = [
    data1,
    [data1, data2],
    (data1, data3),
]
tplot(tvars)
Example block output

tplot also supports plotting on GridPosition and GridSubposition objects

Function as tplot argument for interactive exploration

tplot can handle functions that accept time intervals as arguments. This allows for creating interactive plots where data is dynamically fetched. So instead of the two-step process:

  1. Fetch data: da = f(t0, t1)
  2. Plot data: tplot(da)

We can combine these steps into a single command:

tplot(f, t0, t1)

This approach enables efficient interactive exploration of time series.

Note

For real-time interactivity, consider using the GLMakie backend instead of CairoMakie although it is possible to use tlims! or xlims! to update the plot dynamically.

Data Transformation

Before plotting, data goes through a transformation pipeline to ensure it's in a plottable format (e.g., DimArray).

SpacePhysicsMakie.transformFunction
transform(args...; kwargs...)

Transform data into plottable format (e.g., DimArray).

Extend with transform(x::MyType) for custom types.

source

You can extend the transformation system by defining methods for your types:

transform(x::MyType) = DimArray(x.data)

API

SpacePhysicsMakie.DEFAULTSConstant
DEFAULTS

A global constant that holds default parameters:

  • add_title::Bool defaults to false.
  • add_colorbar::Bool defaults to true.
  • delay : in seconds, the time interval between updates. Default is 0.25.
  • resample::Int : the number of points to resample to. Default is 6070.
source
SpacePhysicsMakie.DebouncerType
Debouncer

A struct that creates a debounced version of a function f.

The debounced function will only execute after a specified delay (in seconds) of inactivity. If called again before the delay expires, the timer resets.

source
SpacePhysicsMakie.FunctionPlotType

FunctionPlot is the plot type associated with plotting function functionplot. Check the docstring for functionplot for further information.

source
SpacePhysicsMakie.MetadataSchemaType
MetadataSchema

Abstract type for defining how metadata keys map to plot attributes. Each concrete schema defines the mapping rules for a specific metadata standard.

source
SpacePhysicsMakie.MultiAxisDataType
MultiAxisData(primary, secondaries...; metadata=nothing)

A type for handling multiple y-axes where the first element is the primary axis (left) and subsequent elements are secondary axes (right side, with increasing padding).

Fields

  • primary: Data for the primary (left) y-axis
  • secondaries: Tuple of data for secondary (right) y-axes
  • metadata: Optional metadata (e.g., title)

Example

# Three axes: one primary, two secondary
data = MultiAxisData(y1_data, y2_data, y3_data)
tplot(data)
source
SpacePhysicsMakie.SpecPlotType

SpecPlot is the plot type associated with plotting function specplot. Check the docstring for specplot for further information.

source
SpacePhysicsMakie._intersectMethod
_intersect(d, itr...)

Find common key-value pairs across multiple dictionaries dicts. Only includes pairs where the key exists in all dictionaries with the same value.

source
SpacePhysicsMakie.add_labels!Function

Add labels to a figure, automatically searching for blocks to label.

Notes

  • https://github.com/brendanjohnharris/Foresight.jl/blob/main/src/Layouts.jl#L2
source
SpacePhysicsMakie.binedgesMethod
binedges(centers; transform=identity)

Calculate bin edges from bin centers.

  • For linear spacing, edges are placed halfway between centers.
  • For transformed spacing, edges are placed halfway between transformed centers.

Arguments

  • transform: Function to transform the space (e.g., log for logarithmic spacing)

Example

centers = [1.0, 2.0, 3.0]
edges = binedges(centers)               # Returns [0.5, 1.5, 2.5, 3.5]
edges = binedges(centers, transform=log)  # Returns edges in log space
source
SpacePhysicsMakie.functionplotFunction

No docstring defined.

Plot type

The plot type alias for the functionplot function is FunctionPlot.

Attributes

plotfunc = tplot_panel!No docs available.

source
SpacePhysicsMakie.isspectrogramMethod
isspectrogram(A::AbstractMatrix; threshold=8, schema=get_schema(A))

Determine if data should be plotted as a spectrogram using the metadata schema.

source
SpacePhysicsMakie.multiaxisplotMethod
multiaxisplot(gp, primary, secondaries...; pad_increment = 50.0, [colors, styles, plottypes, axis], kwargs...)

Create a plot with one primary y-axis (left) for primary and multiple secondary y-axes (right) for secondaries....

Each secondary axis is offset to the right with increasing padding of pad_increment to avoid overlap.

Attributes

  • colors: Vector of colors for each axis (default: Wong color palette)
  • styles: Vector of NamedTuples with plot attributes for each secondary axis
  • plottypes: Plot types to use, a single type would be broadcasted to all axes
source
SpacePhysicsMakie.multiplot!Method
multiplot!(ax, fs, t0, t1; plotfunc=plot2spec, kwargs...)

Specialized multiplot function for functionplot. Merge specs before plotting so as to cycle through them.

source
SpacePhysicsMakie.multiplotMethod
multiplot(gp, tas::MultiPlottable, args...; axis=(;), kwargs...)

Setup the panel on a position and plot multiple time series on it

source
SpacePhysicsMakie.plotfuncFunction

Determine the plotting function for a given data type. Extend this for custom data types to integrate with the plotting system.

source
SpacePhysicsMakie.plotfunc!Function

Determine the plotting function for a given data type. Extend this for custom data types to integrate with the plotting system.

source
SpacePhysicsMakie.prioritized_getFunction
prioritized_get(container, keys, default=nothing)

Extract a value from a container using a prioritized list of keys. Returns the first non-nothing value found, or default if none found.

source
SpacePhysicsMakie.resampleMethod
resample(arr, n=DEFAULTS.resample; dim=1, verbose=false)

Resample an array along the dimension dim to n points. If the original length is less than or equal to n, the original array is returned unchanged.

source
SpacePhysicsMakie.specplot!Function

specplot! is the mutating variant of plotting function specplot. Check the docstring for specplot for further information.

source
SpacePhysicsMakie.tlims!Method
tlims!(ax, tmin, tmax)
tlims!(tmin, tmax)
tlims!(trange)

Set axis limits, handling different time formats. Supports DateTime, Unitful, and numeric time values.

source
SpacePhysicsMakie.tplotMethod
tplot(f, tas; legend=(; position=Right()), link_xaxes=true, link_yaxes=false, rowgap=5, kwargs...)

Lay out multiple time series across different panels (rows) on one Figure / GridPosition f

If legend is nothing, no legend will be added to the plot. Otherwise, legend can be a NamedTuple containing options for legend placement and styling. By default, the time series are transformed via extensible transform.

See also: tplot_panel, transform

source
SpacePhysicsMakie.tplot_panel!Method
tplot_panel!(ax, args...; kwargs...)

Generic entry point for adding plots to an existing axis ax.

Transforms the arguments to appropriate types and calls the plotting function. Dispatches to appropriate implementation based on the plotting trait of the transformed arguments.

source
SpacePhysicsMakie.tplot_panelMethod
tplot_panel(gp, args...; kwargs...)

Generic entry point for plotting different types of data on a grid position gp.

Transforms the arguments to appropriate types and calls the plotting function. Dispatches to appropriate implementation based on the plotting trait of the transformed arguments.

source
SpacePhysicsMakie.transformMethod
transform(args...; kwargs...)

Transform data into plottable format (e.g., DimArray).

Extend with transform(x::MyType) for custom types.

source
SpacePhysicsMakie.x2tMethod

Convert x to DateTime

Reference:

  • https://docs.makie.org/dev/explanations/dim-converts#Makie.DateTimeConversion
  • https://github.com/MakieOrg/Makie.jl/issues/442
  • https://github.com/MakieOrg/Makie.jl/blob/master/src/dim-converts/dates-integration.jl
source