figure
figure
#
Figure — a raster chart drawn with matplotlib and kept as a PNG cg.Image.
- Open. Entering the
withblock lays out one or more stacked panels in the house style: white paper, dark ink, type a phone can read at full width. - Draw. The body draws on
figure.axes(orfigure.panels) with matplotlib's own vocabulary. - Keep. Leaving the block renders the figure into
figure.image, a PNG in the current call's workspace — the value an interceptor serves to the app orImageViewershows on a page.
DPI = 100
module-attribute
#
Pixels per inch: a figure width pixels wide is width / DPI inches.
INK = '#212529'
module-attribute
#
Text, axes and the default line colour.
MUTED = '#6c757d'
module-attribute
#
Tick labels and other secondary text.
RULE = '#dee2e6'
module-attribute
#
Grid lines.
STYLE = {'figure.facecolor': 'white', 'axes.facecolor': 'white', 'axes.edgecolor': INK, 'axes.labelcolor': INK, 'axes.titlecolor': INK, 'axes.spines.top': False, 'axes.spines.right': False, 'axes.grid': True, 'grid.color': RULE, 'grid.linewidth': 1.0, 'xtick.color': MUTED, 'ytick.color': MUTED, 'text.color': INK, 'font.size': 18, 'axes.titlesize': TITLE_SIZE, 'axes.labelsize': 18, 'legend.fontsize': 16, 'legend.frameon': False, 'lines.linewidth': 3}
module-attribute
#
The house style: plain, high-contrast, and legible on a phone at full width.
TITLE_SIZE = 26
module-attribute
#
The title's size, in points.
Figure
#
A matplotlib figure that becomes a PNG cg.Image when its with block ends.
@cg.pure_function("coverage_chart/1")
def coverage_chart(hours: cg.Array[float], need: cg.Array[float]) -> cg.Image:
with cgui.Figure("When to photograph") as figure:
figure.axes.plot(list(hours), list(need))
figure.axes.set_xlabel("Hour")
return figure.image
Source code in capturegraph-ui/capturegraph_ui/figures/figure.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
axes
property
#
The first (or only) panel.
image
property
#
__enter__()
#
Take the house style and lay out the panels.
Source code in capturegraph-ui/capturegraph_ui/figures/figure.py
__exit__(kind, error, traceback)
#
Render the figure into image unless the block raised, then release the style.
Source code in capturegraph-ui/capturegraph_ui/figures/figure.py
__init__(title=None, *, width=1200, height=900, panels=(1.0,))
#
A figure to draw in a with block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str | None
|
A short title over the figure. |
None
|
width
|
int
|
The image's width, in pixels. |
1200
|
height
|
int
|
The image's height, in pixels. |
900
|
panels
|
Sequence[float]
|
The relative height of each panel, top to bottom; panels share their horizontal axis. |
(1.0,)
|