python - 当我将标签位置添加到 python pptx 甜甜圈图时,文件出错
问题描述
我尝试为圆环图添加标签。一切正常,直到我尝试设置标签的位置。既不BEST_FIT
也不OUTSIDE_END
工作。当我添加data_labels.position = XL_LABEL_POSITION.BEST_FIT
行时,文件将无法打开。这是代码:
from pptx import Presentation
from pptx.chart.data import ChartData
from pptx.enum.chart import XL_CHART_TYPE, XL_LABEL_POSITION
from pptx.util import Inches, Pt
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6]) # blank slide
chart_data = ChartData()
chart_data.categories = ['aaa','bbb', 'ccc','ddd', 'eee', 'fff','ggg','hhh', 'iii', 'jjj','kkk','lll','mmm', 'nnn']
chart_data.add_series('Test', [10,50,60,30,5,35,10,15,70,1,10,5,60,30])
x, y, cx, cy = Inches(1), Inches(1), Inches(8), Inches(6)
chart = slide.shapes.add_chart(XL_CHART_TYPE.DOUGHNUT, x, y, cx, cy, chart_data).chart
chart.plots[0].has_data_labels=True
data_labels = chart.plots[0].data_labels
data_labels.font.size = Pt(12)
data_labels.show_percentage = True
data_labels.show_category_name = True
data_labels.show_value = True
data_labels.position = XL_LABEL_POSITION.BEST_FIT
#or
#data_labels.position = XL_LABEL_POSITION.OUTSIDE_END
prs.save('test.pptx')
可以想象,我的真实数据类别名称要长得多,如果没有适当的定位,就无法阅读。那么如何设置标签的位置以便它们可读呢?
解决方案
推荐阅读
- node.js - NodeJS图像未上传且类别名称显示变量而不是值
- r - 如何对另一个子集进行子集化或“分组”?
- html - 如何防止此 HTML 文本换行?
- php - 为什么单例数据库类不需要销毁 PDO?
- mysql - SQL 列可以根据其他表中的条件自动更新吗?
- java - 检查二维 ArrayList 是否包含特定的 ArrayList - Java
- android - 如何解析json对象retrofit2 mvvm中的json数组
- c - 这个函数如何工作“abcdefghijklmnopqrstuvwxyz”[rand()%26]?
- makefile - 有没有办法将多个目标作为一系列单一的 make 调用?
- java - Maven Spring lombok @AllArgsConstructor 不工作