composeui.core.chartimage

A chart as a report’s figure, drawn by matplotlib alike on every backend, or with none.

A screen chart follows its window and theme; a report’s figure has its page’s size and fonts, and a light background. So the figure is drawn from the ChartView’s data, e.g. by a batch run writing a report’s figures:

save_chart_image(chart, Path(“pressure.pdf”), ImageOptions(width_mm=80))

It needs the report extra (matplotlib), imported only by these functions; without it they raise an ImportError naming the extra, and is_available is False.

class composeui.core.chartimage.ImageOptions[source]

Bases: object

How a chart’s image looks: its size, fonts and range.

width_mm: float

an A4 page’s text width

height_mm: float
dpi: int

the resolution of a PNG; a vector image has none

font_size: float

points, as the report’s body text

show_title: bool

a report usually captions its figures itself

x_range: tuple[float, float] | None

the region shown, e.g. the one the user zoomed into; None: all the data

y_range: tuple[float, float] | None
__init__(width_mm=160, height_mm=100, dpi=300, font_size=9, show_title=False, x_range=None, y_range=None)

Method generated by attrs for class ImageOptions.

Parameters:
Return type:

None

composeui.core.chartimage.chart_figure(chart, options=ImageOptions(width_mm=160, height_mm=100, dpi=300, font_size=9, show_title=False, x_range=None, y_range=None))[source]

Draw chart as a report’s figure, which app code can add to before saving it.

Save it in image_style for its text to stay text, or with save_chart_image.

Parameters:
Return type:

Figure

composeui.core.chartimage.save_chart_image(chart, path, options=ImageOptions(width_mm=160, height_mm=100, dpi=300, font_size=9, show_title=False, x_range=None, y_range=None))[source]

Save chart’s figure to path, in the format its suffix names (see FORMATS).

Parameters:
Return type:

None