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:

ArgumentDefaultMeaning
layout"auto""circle" (up to 12 genes), "force" (beyond), or "layered" with regulators above targets
labelsTrue up to 60 genesShow gene labels
curvature0.12Edge bend as a fraction of edge length (reciprocal edges bend at least 0.22)
axnew figureDraw into an existing Axes, for your own tiled layouts
title, legendTrueShow the title line and the activation/repression key
seed1Seed for the force layout
fig = grn.plot_network(model, layout="layered")
grn.export_figure(fig, "network.pdf")           # vector
One 12-gene network in the three layouts. Circle keeps every node visible; force pulls connected genes together; layered puts regulators above their targets.
One 12-gene network in the three layouts. Circle keeps every node visible; force pulls connected genes together; layered puts regulators above their targets.

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.

ArgumentDefaultMeaning
cell0Which cell to draw in full
max_lines12Maximum number of traces
overlayTrueDraw 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")
A custom figure: house-style traces with the network drawn into an inset axes through the ax argument.
A custom figure: house-style traces with the network drawn into an inset axes through the ax argument.