Figures
The {figure} directive puts an image, a notebook cell’s output or a widget in a numbered figure with a caption. It can also:
Nest figures in a figure to make panels, and lay them out on a grid with
:layout:.Keep a figure’s print image, the whole figure as one picture, and mark where each panel is on it with
:regions:.Link a figure or a panel to the code and data behind it with
:code:and:data:.Give a figure a
:title:.Show a static image in place of an interactive notebook output until a reader opens the panel, with
:placeholder:.
These options need the CLI’s Curvenote {figure}, which is in Early Access: run the CLI with CURVENOTE_FIGURE=1, as in CURVENOTE_FIGURE=1 curvenote start. Without it, the CLI uses MyST’s {figure}, and warns about each option it doesn’t know.
On a Curvenote site, these figures are shown as a Curvenote Figure: readers step through the panels, open the figure full screen and zoom in. Curvenote Figure is in Early Access. On a site without it, panels stack and the links are part of the caption.
Panels¶
A figure nested in a figure is a panel of it. Each panel has its own content, caption and label. The outer figure’s caption is the caption of the whole figure.
::::{figure}
:label: fig-growth
:layout: 2
:::{figure} images/bars.svg
:label: fig-growth-a
Counts per condition.
:::
:::{figure} images/heatmap.svg
:label: fig-growth-b
Correlation between conditions.
:::
**Growth across conditions.** Two panels side by side.
::::Refer to the whole figure with [](#fig-growth) (“Figure 1”) and to a panel with [](#fig-growth-b) (“Figure 1b”). A panel can hold anything a figure can: an image, a notebook cell’s output (#my-cell), a table or an {anywidget}. The outer figure needs four colons when its panels use three, as above.
Laying out panels¶
:layout: places the panels on a grid. Without it, they stack in one column.
| You want | Layout |
|---|---|
| One row | row |
| Equal columns | 2, 3 |
| Columns of different widths | 30 70 |
| A gap between columns | 40 g10 50 |
| A map of where each panel is | a a b | c d e |
| Widths and a map | 30 70 : a b | a c |
| An empty cell in a map | a . | b c |
Letters are positions:
ais the first panel,bthe second, whatever the panels are labeled. A letter repeated across cells makes that panel span them, as long as its cells form a rectangle.Rows of a map are separated by
|, and every row needs the same number of cells.Widths are relative:
30 70,3 7and1 2all work. A gap (g10) is in the same units, and goes between two columns.Every panel must be in the map, and every letter in the map must be a panel.
For example, a a b | c d e gives the first panel two of the three columns in the first row. 30 70 : a b | a c makes a narrow first column, with the first panel down both rows of it.
Different screens¶
A layout that suits a wide screen may not suit a phone. Give the layout for other widths with these options:
| Option | Screen | About | If you leave it out |
|---|---|---|---|
:layout-sm: | Small | 375px | It uses :layout-md: |
:layout-md: | Medium | 768px | It uses :layout: |
:layout: | Large | 1024px | The panels stack |
:layout-xl: | Extra large | 1440px | It uses :layout: |
:::::{figure}
:label: fig1
:layout: a a a b | c d e e
:layout-md: a a a | b c d | e e e
:layout-sm: 1A layout the CLI can’t read is left out with a warning that names the option and the problem, for example Row 2 has 1 cells for a map whose rows differ. The figure still builds; that screen falls back as in the table.
A figure on its print image¶
Many papers have figures made for print: one image with all the panels drawn on it. Keep that image as the figure, nest a figure for each panel, and mark where each panel is on the image with :regions::
:::::{figure} images/fig1-print.png
:label: fig1
:regions: 0 0 75 49; 75 0 100 50.5; 0 50.5 25 100; 25 50.5 46.5 100; 46.5 50.5 100 100
::::{figure}
:label: fig1a
Embryos were staged and processed across 36 time points.
::::
::::{figure} #nb-fig1b
:label: fig1b
The number of cells profiled at each time point.
::::
...
A single-cell time-lapse of mouse development.
:::::One box per panel, in order, separated by
;. A box isx1 y1 x2 y2: its top-left and bottom-right corners, in percent of the image’s width and height.Letters are optional: a box can start with its panel’s letter (
b 75 0 100 50.5). If one does, they all must.A panel can give its own box with
:region:, which wins over the outer figure’s:regions:.Without any regions, a figure’s image is its first panel, and the nested figures follow it.
A panel with no content of its own, like
fig1aabove, is its part of the print image: opening it zooms in. A panel with content, likefig1b, shows that content when it’s opened, with a map of the print image beside it.
PDFs and other static exports use the print image, as the paper did. On a figure with regions, the figure’s image is its print image, so a :placeholder: on the outer figure is ignored with a warning.
Links to the code and data¶
:code: and :data: link a figure, or a panel, to what made it. Each takes a path in the project or a URL.
::::{figure} #nb-fig1c
:label: fig1c
:code: notebooks/fig1.ipynb
:data: data/pca.csv
Pseudo-bulk ATAC-seq profiles on the top two principal components.
:::::code:is the notebook or script that made the figure. A panel that shows a notebook cell’s output already links to its notebook, so it doesn’t need one.:data:is the data the figure plots. A file in the project, such as a CSV, is copied into the site as a download.
A Curvenote Figure shows them as Code and Data buttons. Elsewhere they are links at the end of the caption.
A title¶
:title: gives a figure a title, in markdown. A Curvenote Figure shows it above the figure, next to its number; the caption stays below.
:::::{figure} images/fig1-print.png
:label: fig1
:title: Mouse development, cell by cellInteractive outputs and their placeholders¶
A notebook output can be interactive, such as a plotly plot or a widget. Give its figure a :placeholder:, a static image of the output:
::::{figure} #plotly-fig-1d
:label: fig1d
:placeholder: images/fig1d-umap.png
3D UMAP of cells co-embedded from scRNA-seq and scATAC-seq.
::::On the page, the figure shows the placeholder. When the figure is a panel, the grid shows the placeholder too, so a page with many interactive panels stays light.
When a reader opens the panel, or steps to it in full screen, the interactive output loads in its place and fills the figure. A “Curvenote Figure” card shows while it loads. Once it has loaded, it stays loaded while the reader is on the page.
PDFs and other static exports use the placeholder.
Make the placeholder the same shape as the output, so the figure doesn’t jump when the output loads.
All the options¶
These are the options on this page. A figure also takes :label:, to refer to it, :alt:, for its alt text, and :width:.
| Option | On | What it does |
|---|---|---|
:layout: | A figure with panels | Where the panels go, on a large screen. More |
:layout-sm:, :layout-md:, :layout-xl: | A figure with panels | The layout on other screens. More |
:regions: | A figure with panels | Where each panel is on the figure’s print image. More |
:region: | A panel | Where this panel is on the print image. More |
:code: | A figure or a panel | A link to the code that made it. More |
:data: | A figure or a panel | A link to its data, copied into the site. More |
:title: | A figure | A title, shown above the figure. More |
:placeholder: | A figure with an interactive output | A static image, shown until a reader opens it. More |
Examples¶
The figures example project has every option on this page. It includes a real paper’s Figure 1, laid out from images and notebook outputs and shown again on its print image.