Output and reproduction scripts

For ClimCanvas v1.02.1

This chapter describes how to export a figure as an image, a video or a Python script. The export controls are below the figure in the main area; only the animation settings are in the "Time" section of the sidebar.

Saving still images

These are the items under "Image export" in the main area.

Item Description Default
Output format PNG / JPG / TIFF / SVG / PDF / EPS PNG
Resolution (dpi) 150 / 300 / 600. In vector formats (SVG / PDF / EPS) it affects only the rasterized elements 300
Output file name The extension is replaced to match the output format figure.png
Background White (default) / Set color / Transparent. The background of the margins outside the plot frame; not reflected in the preview White
Trim margins (bbox_inches="tight") Trims the margins around the figure On
Image export and reproduction script
'Image export' and 'Reproduction script' in the main area.

Time-stepping animation

For horizontal maps, vertical cross-sections and 1-D plots, animations are created from "Time" → "Animation" in the sidebar. Time sections are not eligible because time is their axis.

Item Description Default
Start time / End time First / last
Step (every n) 1 to 100 1
fps (frames/sec) 1 to 10 4
Resolution (dpi) Resolution of each frame (50 to 400). Pixels = Figure size × dpi 100
File format GIF / MP4. MP4 appears only when ffmpeg is found GIF
Animation
'Time' → 'Animation'.

Globe rotation animation

"Motion" appears only when the projection is Orthographic and the figure has a single panel.

Reproduction script

Design

The reproduction script is self-contained Python code that depends only on xarray, numpy, matplotlib and cartopy, so it can be run and edited in an environment without ClimCanvas. The figure drawn inside the app and the figure drawn by the generated script are tested to produce identical images in the same environment. The exception is external colormaps: only when a colormap from cmocean / cmcrameri / cmaps is used does the script import that package.

Structure of the generated script

Under "Reproduction script" in the main area, choose the "netCDF path style" (Absolute paths / Relative paths), "Include savefig" and "Include plt.show()" (both on by default), and save with "Download script". The file name is the output file name with its extension changed to .py. The content can be inspected with "Show generated script" directly below the figure. Relative paths are relative to the directory where the app was started.

The script is laid out from top to bottom in this order.

  1. A one-line description (the version of ClimCanvas that generated it).
  2. Only the imports needed (matplotlib, numpy, xarray, cartopy, etc.).
  3. Imports of external colormaps, registration of custom colormaps and embedded functions (only when needed).
  4. Data loading such as ds0 = xr.open_dataset(...). Calendar conversion, attaching coordinate files and dimension name alignment are written out with the same content.
  5. Creation of the Figure, the axes and layer drawing of each panel, colorbars and annotations.
  6. fig.savefig(...) and plt.show(). The savefig arguments carry over the format, resolution, background and margin settings of "Image export" as they are.
Generated script
'Show generated script' opened (example with one fill layer).
$ python figure.py

Running it creates the figure file in the same directory. The drawing of each panel is an independent block, so blocks can be deleted or copied as units. Typical places to edit by hand are the data path, the savefig output name and dpi, figsize and the arguments of each drawing call.

When running on another machine

Fonts depend on the environment; if the same font is not available, matplotlib falls back to its default. The 1:50m / 1:10m geographic data are downloaded by cartopy on first use. Reading netCDF requires an xarray backend such as netCDF4.

External and custom colormaps

Animation reproduction script

"Animation" → "Reproduction script" → "Download animation reproduction script" saves animation.py. It wraps the drawing body in a loop over frames, with the list of times (for rotation, the list of central longitudes and latitudes) written as literals. GIF uses Pillow and MP4 uses ffmpeg, so these must be available in the environment. The netCDF paths are always absolute.

Sessions

Saving and restoring are described in Basics, and the directories where sessions are stored in Usage. This section summarizes the contents and caveats.

Presets

A preset stores your preferred data-independent settings in ~/.climcanvas/preset.json and applies them automatically at the next startup. Save and delete under "Save" → "Preset" in the sidebar (Basics).

Location Settings stored
"言語 / Language" at the top of the sidebar Display language
Figure-wide format → Font Whether to set a font, how to choose, the font
"Image export" below the figure Output format, resolution (dpi), output file name, background (white / set color / transparent) and background color, trim margins
"Reproduction script" below the figure netCDF path style, include savefig, include plt.show()
Map & gridlines → Map settings (horizontal map) Coastlines (show, width, color), country borders, land (fill, color, draw above data), ocean (fill, color), figure frame width
Map & gridlines → Gridlines (lat/lon) Show, lines (show, width, color, style), longitude and latitude intervals, labels (show, sides, longitude labels along the circle and at the pole, latitude label edge, interval, start, rotation, font size, padding)
Map & gridlines → Tick marks Show, longitude and latitude intervals, length, width, orientation, sides, short ticks (add, interval, length, width)
Frame Top/bottom/left/right edges, edge width, edge color
Font sizes Title font size (Text & markers → Title), axis label font size (Labels), tick label font size (Ticks)
Show time Show the time above the plot, position, time format
Animation fps, resolution (dpi), file format
Colormap (fill, contours, vectors, streamlines, scatter (points), track, hexbin, 2-D histogram, bubble chart, heatmap) Colormap group and name, reverse colormap, number of color levels, extend (out-of-range handling). Heatmap: colormap only
Colorbar (layers with a colorbar) Show, position, ticks and label on the opposite side, length, thickness, edge and tick mark widths, gap from the plot, label and tick label font sizes and paddings (the label text is not included)
Contours Line coloring, line color, line width, line styles (positive / negative values), contour labels (show, font size, format)
Hatch Hatch pattern, density, line width, line color, lower and upper bounds
Vectors Coloring and color, grid cells to skip, hide arrows at or below a magnitude threshold (and the threshold), automatic scale and reference vector length, line width, head length, edges (show, color, width), vector key (show, length, label position, font size, position)

Checks before submitting a paper

ClimCanvas is a tool that draws what it is told to, and it is the user's responsibility to confirm that a figure shows what was intended. Before using a figure in a paper or report, we recommend checking the following four points. The numerical assumptions (selection, subsetting, averaging, missing values, definitions of statistics) are summarized in Computational conventions.

  1. Read the box "Processing applied to this figure" below the figure and the data section of the reproduction script. The box lists, per panel and only when used, the value transforms (scale a and offset b per variable, with the variable's units attribute), range means (dimension, range, arithmetic or cos(lat)-weighted, number of grid points included, number of missing values within the range), mask-out thresholds, and that vector components are not rotated on a 2-D coordinate grid. It also reports when the main quantity has a value transform that is not applied to the error quantity (also when the units attributes of the error variable and the main variable differ), and when quantities with different units attributes or value transforms are overlaid on the same y-axis of a 1-D plot (the secondary axis and the x-axis of horizontal bars are treated separately). Since units attributes are compared as strings, mere differences in spelling such as "m/s" and "m s-1" are also reported as "may differ". Fixed coordinate values appear verbatim as actual values in .sel(...), and range means in the .mean(...) line (.weighted(...) when cos-weighted) together with the averaged dimensions (Structure of the generated script). These few lines let you confirm that the level, time, range and weighting are as intended.
  2. Compare the plotted values with your own calculation. If you print the array passed to the drawing call in the reproduction script or write it out with to_netcdf, you can compare it with values obtained with GrADS, CDO or your own scripts. Checking even a single point of a range mean, zonal mean or unit conversion reveals mistakes in selection or weighting.
  3. Record the version you used. The version is written in the first line of the reproduction script. Keep a note of which version was used to make the figure. When citing in a paper, cite with the version. How to use the DOIs (the concept DOI shared by all versions and the version DOIs of milestone versions) and citation examples are in Install: citation.
  4. Check the known bugs. Bugs that affect the plotted values are listed in KNOWN_ISSUES.md in the repository together with the affected versions and features. Check before submission, and when a fixed version is released after publication, whether your version and the features you used are affected.

Do not rely too much on the box 'Processing applied to this figure'

The box is an aid for preventing mistakes. It cannot find every mistake. An empty box is no guarantee that the figure is correct. For example, units are compared only as strings of the units attribute, so the same unit written differently (m/s and m s-1) is also reported as "may differ". Conversely, for data without a units attribute, or for combinations outside the check such as several layers of 1-D aggregation or scatter plots, nothing is shown even when the units disagree. Do not rely on the box alone; verify the plotted values yourself as in point 2 above.