Jan*_*uGe 13 python graphics plot powerpoint r
我正在使用officer和rvg软件包将R中的图表作为可编辑矢量图形从MS PowerPoint中获取.下面的可重复示例.
我正在寻找一种方法来实现与python的等效解决方案,最好使用matplotlib.关键部分不是从IDE创建幻灯片,而是可编辑的矢量图形部分,即绘图最终应该在PowerPoint中作为由一系列简单的powerpoint几何(如线,正方形和文本字段)组成的分组对象.
R例子:
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')
Run Code Online (Sandbox Code Playgroud)
生成的图表完全可编辑:
自 2019 版 MS Office 起,您可以将svg文件添加为图像,然后取消分组以使其可编辑。请参阅此MS 页面上的“将 SVG 图像转换为 Office 形状” 。然而,根据我个人的经验,这既不是很稳定,也不是很完整。
另一种更稳定、更完整的方法,尽管仍然不完美,是将其作为emf文件导入到 powerpoint 中,这也是一种矢量格式。旧版本的 matplotlib 可以导出为这种格式。对于较新的版本,我导出为svg,然后使用inkscape --file "input.svg" --export-emf "output.emf"转换为emf,然后将其加载到 powerpoint 中。如果一切正常,再次取消对象分组即可进行编辑。
| 归档时间: |
|
| 查看次数: |
477 次 |
| 最近记录: |