Python · chapter 8 of 13
Figures
Every plotting function returns a Matplotlib Figure and follows one house style (palette, typography, tick and grid styling). Pair them with grn.export_figure for publication output. grn.style() returns the palette and sizes for your own plots.
Networks: grn.plot_network
fig = grn.plot_network(model) accepts a Model, a Solution, a Screen, a Motif, or a signed adjacency. It draws the network in pathway notation:
- Activation ends in a filled arrowhead, repression in a bar.
- Autoregulation is a loop bulging away from the network's centre.
- Reciprocal edges curve apart so both directions stay visible.
- Node size grows with the number of targets, so hub regulators stand out.
- Labels sit inside the nodes up to 12 genes and beside them beyond that, placed in the emptiest direction.
| Argument | Default | Meaning |
|---|---|---|
layout | "auto" | "circle" (up to 12 genes), "force" (beyond), or "layered" with regulators above targets |
labels | True up to 60 genes | Show gene labels |
curvature | 0.12 | Edge bend as a fraction of edge length (reciprocal edges bend at least 0.22) |
ax | new figure | Draw into an existing Axes, for your own tiled layouts |
title, legend | True | Show the title line and the activation/repression key |
seed | 1 | Seed for the force layout |
fig = grn.plot_network(model, layout="layered")
grn.export_figure(fig, "network.pdf") # vector

Motif gallery: grn.plot_motifs
grn.plot_motifs() draws all ten registered motifs; grn.plot_motifs(["toggle", "repressilator"]) a subset. Arguments columns (5) and size (4, for cascade and sim).
Expression data: grn.plot_expression
fig = grn.plot_expression(sol, ...) shows a solution as line traces (all genes up to max_lines, otherwise the most variable ones) over a genes-by-time heat map. When the solution has several cells, the chosen cell is drawn in full and the others as faint traces behind it. When a stimulus was applied, a top panel shows the input.
| Argument | Default | Meaning |
|---|---|---|
cell | 0 | Which cell to draw in full |
max_lines | 12 | Maximum number of traces |
overlay | True | Draw the other cells faintly (up to 50 cells) |
species | "protein" | "protein" or "mrna" for two-stage models |
Export: grn.export_figure
grn.export_figure(fig, filename) applies the house style and writes the file. .png, .jpg, .tif are rasterised at resolution dpi (default 300); .pdf, .eps, and .svg are vector graphics. style=False skips the restyling.
grn.export_figure(fig, "figure3.png", resolution=600)
grn.export_figure(fig, "figure3.pdf")
Headless environments work with Matplotlib's Agg backend (matplotlib.use("Agg") before importing pyplot).
Building your own figure
The style constants are available for custom plots:
import matplotlib.pyplot as plt
st = grn.style() # st["colors"] (7 x 3), st["gray"], st["line_width"], ...
fig, ax = plt.subplots(figsize=(9, 3.6))
ax.plot(sol.t, sol.x[:, 0], color=st["colors"][0], lw=st["line_width"])
inset = fig.add_axes([0.72, 0.5, 0.22, 0.4])
grn.plot_network(model, ax=inset, title=False, legend=False)
grn.export_figure(fig, "custom.pdf")
