当前位置:网站首页>openpyxl绘制饼图
openpyxl绘制饼图
2022-07-15 17:33:00 【奋斗中的打工人】
效果

代码
from openpyxl import Workbook
from openpyxl.chart import (
PieChart,
ProjectedPieChart,
Reference
)
from openpyxl.chart.series import DataPoint
data = [
['Pie', 'Sold'],
['Apple', 50],
['Cherry', 30],
['Pumpkin', 10],
['Chocolate', 40],
]
wb = Workbook() # 新键wb对象
ws = wb.active # 选择活跃的单元表
for row in data:
ws.append(row)
pie = PieChart()
labels = Reference(ws, min_col=1, min_row=2, max_row=5)
data = Reference(ws, min_col=2, min_row=1, max_row=5) # 图表数据区域
pie.add_data(data, titles_from_data=True)
pie.set_categories(labels)
pie.title = "Pies sold by category" # 图表标题
slice = DataPoint(idx=0, explosion=20)
pie.series[0].data_points = [slice]
ws.add_chart(pie, "D1")
wb.save("pie.xlsx")
边栏推荐
- 缓存穿透、缓存雪崩、缓存击穿?
- (shangsilicon Valley) JDBC general review
- (尚硅谷)JDBC总复习
- 美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃?
- Can you use redis? Then come and learn about redis protocol
- Queue(单项队列)和Deque(双端队列)的知识点整理
- Openharmony module II parsing of header files under interfaces (8)
- OpenHarmony模块二初分析
- 实现一下几个简单的loader
- Pytorch中torch.nonzero()函数解析
猜你喜欢
随机推荐
万物皆可Cassandra——HUAWEI Tag背后的神仙数据库
分库分表真的适合你的系统吗?聊聊分库分表和NewSQL如何选择
Redis distributed lock: what have you experienced from Xiaobai to Dashen?
Markdown in CSDN sets the width of table columns
How to migrate the complex SQL statements used by applications developed for Oracle to polardb for POS
OpenHarmony模块二下文件samgr_server解析(5)
Sorting out knowledge points of queue (single queue) and deque (double ended queue)
Parsing of header files under interfaces in module 2 (3)
OpenHarmony安全模块之AES加密学习
OpenHarmony模块二下文件samgr_server解析(2)
Pytorch中torch.max()函数解析
[Mori city] random talk on GIS data (IV) - coordinate system
美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃?
[brother hero July training] day 15: depth first search
Redis 分布式锁:从小白到大神方案都经历了什么?
会用redis吗?那还不快来了解下redis protocol
Unit MySQL appears in MySQL Solution of service could not be found
如何制作sitemaps网站地图
OpenHarmony模块二初分析
1. Huawei machine test question record








