Skip to content

Figures for papers

A figure for a paper must match the page: vector, at the column width, in the paper’s font. optodraw writes SVG, TikZ for LaTeX and the 1D schematic.

The ODMR microscope of Babashah et al. (2023), Fig. 4, in 2D:

The ODMR microscope of Babashah et al., SciPost Phys. Core 6, 065 (2023), Fig. 4, for a paper
# The ODMR microscope of Babashah et al., SciPost Phys. Core 6, 065 (2023), Fig. 4, for a paper
from optodraw import Beam, BeamSplitter, Filter, Laser, Lens, Objective, Photodiode, Sample, Scene
from optodraw.layout import aim
scene = Scene(title="ODMR setup", platform="free_space")
scene.set_view_layout({"3d": {"spacing": "auto"}}) # 3D: room for every post; 1D and 2D stay compact
pump = scene.add(Laser(center=(-38, 0), wavelength=532, label="Laser"))
dichroic = scene.add(BeamSplitter(center=(0, 0), dichroic=True, cutoff_wavelength=600, label="Dichroic mirror"))
objective = scene.add(Objective(center=(0, -13), angle=-90, label="Objective"))
sample = scene.add(Sample(center=(0, -26), angle=-90, label="Sample")) # turned to face the objective
filt = scene.add(Filter(center=(0, 10), angle=90, label="IF filter"))
lens = scene.add(Lens(center=(0, 20), angle=90, label="Lens"))
pd = scene.add(Photodiode(center=(0, 31), angle=90, label="Photodetector"))
aim(dichroic, pump, objective)
for part in (dichroic, objective, sample, filt, lens, pd):
part.label_side = "right"
# the green pump goes down and the red photoluminescence comes back up the same axis (drawn narrower)
scene.add(Beam.through(pump, dichroic, objective, (sample, "in"), wavelength=532, width=1.0))
scene.add(Beam.through((sample, "in"), objective, dichroic, filt, lens, pd, wavelength=690, width=0.45))
scene.fit_frame(margin=8)
scene
The ODMR microscope of Babashah et al., SciPost Phys. Core 6, 065 (2023), Fig. 4, for a paper in 2D

As TikZ: \input the file, and its labels take the paper’s font.

TikZ for LaTeX: \input this file and the figure takes the paper's own font
# TikZ for LaTeX: \input this file and the figure takes the paper's own font
tikz = scene.render_tikz(standalone=False)
print(tikz[:700], "...")
% od-core.tex : shared base of the optodraw 1D symbol library.
% Colors, line styles, the /od/ key family, the port macro and the read-back
% macros. Family files (od-onchip.tex, ...) hold one pic per component and are
% loaded after this file. The library needs TikZ and nothing else.
\usetikzlibrary{calc,arrows.meta}%
% Line art is black. Color carries a fixed meaning and nothing else.
\definecolor{odheat}{HTML}{F0E442}% heater metal
\definecolor{odp}{HTML}{E8615F}% p doping (light red)
\definecolor{odn}{HTML}{56B4E9}% n doping (light blue)
\definecolor{odw1}{HTML}{0072B2}\definecolor{odw2}{HTML}{009E73}% wavelengths
\definecolor{odw3}{HTML}{E69F00}\definecolor{odw4}{HTML}{CC79A7}%
\newif\i ...

The first cell’s 1D tab is the schematic: each part as its symbol.

A Page is a scene in millimetres that prints at its exact size. An Inset holds one item: a scene, a section, a plot, a picture, an SVG or PDF file, text or an equation.

A page of insets: a bench, a plot, a picture and a section, with a calloutsaved output
# A page of insets: a bench, a plot, a picture and a section, with a callout
import io
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
from optodraw import Callout, Image, Page, SectionView
from optodraw.gds import stack_section
from PIL import Image as Pixels
page = Page(width_mm=183)
plt.rcParams.update({"font.size": 6})
fig, ax = plt.subplots(figsize=(1.8, 1.4), layout="constrained")
ax.plot([0, 1, 2, 3], [0, 1, 4, 9])
ax.set_xlabel("x (a.u.)")
ax.set_ylabel("y (a.u.)")
# the same waveguide as an SEM-like render, 12 um wide: pixels, kind="render" (a photo is kind="measured", 300 ppi up)
wide = stack_section("gdsfactory_generic", (1, 0), width=0.5, window=(0.0, 12.0))
picture = Image(np.asarray(Pixels.open(io.BytesIO(wide.png(width_px=900)))), kind="render")
section = SectionView(stack_section("gdsfactory_generic", (1, 0), width=0.5))
bench, chart, photo, cut = page.row([scene, fig, picture, section])
page.add(Callout("Core", center=cut.at(7.4, 2.2), target=cut.at(6.0, 0.11)))
page
A page of insets: a bench, a plot, a picture and a section, with a callout in 2D

page.row sets items at one height. A picture stays pixels in a vector frame. A callout on inset.at(x, y) moves with its inset. page.export("fig") writes SVG, and PDF and PNG with the figure extra.

Call Gives
scene.render_svg("fig.svg") 2D drawing as SVG
scene.render_tikz("fig.tex", standalone=False) TikZ to \input in a paper
scene.export_figure("fig", width_mm=89) SVG, PDF and PNG at their size on the page
export_panels("fig", [[bench, "plot.svg"]], width_mm=183) Lettered panels from scenes, sections and files
"f_p, *k*, cm^2" Scripts and italics in any label
Callout("Gap", center=(20, 18), target=ring.anchor("gap")) Text with a line to a part
Bracket("Telescope", l1, l2), DashedLink(a, b) A named span; two places tied
SectionMark(a, b), Region(parts, label="TX") A cut line; a named group
page.zoom(small, region, big) A closer view tied to its place
Glyph.on(beam, "pulse", leg=2) The signal state beside a beam
check_export("fig.svg") The file measured at print size
Timing(rows, span=(0, 8)), eye_diagram(samples, 16) Timing and eye diagrams
stack_section(stack, (1, 0)), xs.beam(wavelength=450) A chip section from a stack, with a beam
GdsView(gds, stack, region), inset.cut(a, b) A GDS crop as vector; its section along A-A′
View3D(scene), View3D.chip(gds, stack) A scene or a chip in 3D, as vector
Scene(beam_style=BeamStyle(opacity=0.5, scale=1, by_wavelength=1)) The look of all the light
build_publication_bundle(scene, output_dir=..., formats=(...)) SVG, TikZ, PNG and a caption in one folder
scene.fit_frame(margin=...) A frame around all parts and beams

Every part has a 1D symbol: a real line drawing, never a labelled box. Optical, electrical and fibre links differ without colour, so a figure prints in black and white.

The 2D drawing paints each part from its symbol. The 1D view draws it as line art. TikZ uses the same symbols as a LaTeX library.

Babashah, H. et al. Optically detected magnetic resonance with an open source platform. SciPost Phys. Core 6, 065 (2023). doi:10.21468/SciPostPhysCore.6.4.065