I am using the officer
and rvg
packages to get plots from R into MS PowerPoint as editable vector graphics. Reproducible example below.
I am looking for a way to implement an equivalent solution with python, preferably using matplotlib
. The critical part is not the creation of slides from the IDE but rather the editable vector graphics part, i.e. plots should end up in PowerPoint as grouped objects comprised of a range of simple powerpoint geometries such as lines, squares, and text fields.
R example:
library(tidyverse)
library(officer)
library(rvg)
# Get some data and make a plot
ggp <- diamonds %>%
group_by(clarity) %>%
summarise(price = mean(price)) %>%
ggplot(aes(x = clarity, y = price, fill = clarity)) +
geom_bar(stat = 'identity', colour = 'black')
# Create a new powerpoint document
doc <- read_pptx()
doc <- add_slide(doc, 'Title and Content', 'Office Theme')
# Add the plot
doc <- ph_with_vg(doc, ggobj = ggp, type = 'body')
# Write the document to a file
print(doc, target = 'plots.pptx')
The resulting chart is completely editable:
Since the 2019 version of MS office you can add svg
files as images and then ungroup them to make them editable. See 'Convert an SVG image to an Office shape' on this MS page. In my personal experience, this is however neither very stable nor complete.
Another way, which is more stable and complete although still not perfect, is importing it in powerpoint as emf
file, which is also a vector-format. Old version of matplotlib could export to this format. For newer version, I export as svg
and then use inkscape --file "input.svg" --export-emf "output.emf"
to convert to emf
, which I then load in powerpoint. Ungrouping the object again allows you to edit, if everything works well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With