Python第三方库之openpyxl(10)
雷达图
在工作表上的列或行中排列的数据可以在雷达图中绘制。雷达图比较多个数据系列的总值。它实际上是一个圆形x轴上的面积图的投影。有两种类型的雷达图:standard,该区域用一条线标记;填满了整个区域的位置。additional 类型的“marker”没有效果。如果需要标记,可以为相关的系列设置。
from openpyxl import Workbook
from openpyxl.chart import (
RadarChart,
Reference,
) wb = Workbook()
ws = wb.active rows = [
['Month', "Bulbs", "Seeds", "Flowers", "Trees & shrubs"],
['Jan', 0, 2500, 500, 0,],
['Feb', 0, 5500, 750, 1500],
['Mar', 0, 9000, 1500, 2500],
['Apr', 0, 6500, 2000, 4000],
['May', 0, 3500, 5500, 3500],
['Jun', 0, 0, 7500, 1500],
['Jul', 0, 0, 8500, 800],
['Aug', 1500, 0, 7000, 550],
['Sep', 5000, 0, 3500, 2500],
['Oct', 8500, 0, 2500, 6000],
['Nov', 3500, 0, 500, 5500],
['Dec', 500, 0, 100, 3000 ],
] for row in rows:
ws.append(row) chart = RadarChart()
chart.type = "filled"
labels = Reference(ws, min_col=1, min_row=2, max_row=13)
data = Reference(ws, min_col=2, max_col=5, min_row=1, max_row=13)
chart.add_data(data, titles_from_data=True)
chart.set_categories(labels)
chart.style = 26
chart.title = "Garden Centre Sales"
chart.y_axis.delete = True ws.add_chart(chart, "A17") wb.save("radar.xlsx")