report_add_plot

report_add_plot(doc, plot, width=None, height=None, dpi=PLOT_DPI)

Add a plot to a report.

Renders a chart to an image and places it in the current slide’s content placeholder (pptx) or as a new figure (docx). On slides the image is rendered at exactly the content placeholder’s size, so nothing is stretched or letterboxed; when the template does not define placeholder geometry the slide size (minus margins) is used instead.

Parameters

Name Type Description Default
doc pptx.Presentation or docx.Document A document from report_new(). required
plot plotnine.ggplot A chart. required
width float Image size in inches. None (default) sizes it to the slide’s content placeholder (pptx) or 6 x 3.5 (docx). None
height float Image size in inches. None (default) sizes it to the slide’s content placeholder (pptx) or 6 x 3.5 (docx). None
dpi int Raster resolution. Default 150. PLOT_DPI

Returns

Name Type Description
pptx.Presentation or docx.Document The document.

See Also

report_add_table

Examples

>>> p = plot_bars(calc_percentage(podracing_survey, "demo_gender"))
>>> doc = report_add_slide(report_new("pptx"), "Gender")
>>> doc = report_add_plot(doc, p)