Example Plots
Contents
Example Plots#
This page showcases plot configurations and the resulting output.
Table of Contents
Further reading:
How to include the given examples into your plots
All plot configurations shown here are represented using YAML, which is the most convenient. Note that the examples omit the top-level of the plots configuration file; if you want to use the plots in such a way, include the shown examples like this:
my_plot:
# ... content of the YAML examples you see here ...
By the way: All plots on this page are tested as part of the dantro test suite and are generated dynamically.
Todo
Describe how to generate the test data.
Errorbands plot using meta-operations#
This is similar to an example in the xarray documentation, showing averaged air temperatures over time.
Using the dantro base plots config, this example embeds pre-defined meta-operations which are then used to compute the mean and standard deviation of the example data. In addition, a rolling mean is applied to smoothe out the data, and a coordinate dimension is transformed such that matplotlib can plot label ticks from it.
Plot configuration
based_on:
# select the creator and use the errorbands plot function
- .creator.pyplot
- .plot.facet_grid.errorbands
# include some meta operations
- .dag.meta_ops.compute_mean_and_stddev
- .dag.meta_ops.rolling
- .dag.meta_ops.transform.coords.date2num
# call some pre-defined helpers
- .hlpr.ticks.x.date
- .hlpr.autofmt_xdate
- .hlpr.limits.x.min_max
# always create a DAG visualization
- .dag.vis.defaults
- .dag.vis.always
select:
air_temps:
path: xr_tutorial/arrays/air_temperature
transform:
- .squeeze_with_drop
# for matplotlib to accept this, need to transform the time coords
- .transform.coords.date2num: [!dag_prev , time]
transform:
# Compute the mean and standard deviation using included meta-operation
- compute_mean_and_stddev: [!dag_tag air_temps, [lat, lon]]
# Apply a rolling mean over 10 data points
- rolling.mean: [!dag_prev , {time: 10}]
tag: data
# Specify which data variable to plot as line and which as errorbands
x: time
y: mean
yerr: stddev
# Pretty it up a bit using helpers
helpers:
set_labels:
x: Time
y: Temperature [K]
set_title:
title: Mean Air Temperature
3D scatter plot#
Here, a 3D random walk is visualized using the scatter3d()
plot, accessible via the facet grid interface.
Plot configuration
based_on:
# select the creator and use the errorbands plot function
- .creator.pyplot
- .plot.facet_grid.scatter3d
select:
data: labelled/random_walk_dset
# Specify which data variable to use for which representation mode
x: x
y: y
z: z
hue: time
markersize: speed
# Pretty it up a bit
cmap: cividis
cbar_kwargs:
label: time
fraction: 0.05
shrink: 0.5
Multiplot with subplots#
This example showcases the multiplot function and how to add different content on individual subplots.
Furthermore, it uses the import functionality of the plot function to call matplotlib.pyplot.ylabel()
on the subplots.
Plot configuration
based_on:
- .creator.pyplot
- .plot.multiplot
# use helpers for styling
- .hlpr.limits.x.min_max
- .hlpr.lines.h_zero
# Select some example data
select:
some_data: labelled/time_series
transform:
# Compute mean and std. deviation over the space dimension
- .mean: [!dag_tag some_data, [space]]
tag: mean
- .std: [!dag_tag some_data, [space]]
tag: std
# Explicitly extract coordinates, needed by plt.plot
- .coords: [!dag_tag mean, time]
tag: time_coords
# Use PlotHelper to configure figure to have two subplots
helpers:
setup_figure:
ncols: 1
nrows: 2
sharex: true
set_suptitle:
title: Some Time Series (mean and std)
set_labels:
x: Time
only_label_outer: true
# Specify the multiplot calls on the upper and lower subplots
to_plot:
[0, 0]:
- function: plt.plot
args:
- !dag_result time_coords
- !dag_result mean
- function: [matplotlib.pyplot, ylabel]
args: [mean]
[0, 1]:
- function: plt.plot
args:
- !dag_result time_coords
- !dag_result std
- function: [matplotlib.pyplot, ylabel]
args: [std]