面积图
2D面积图
Area charts are similar to line charts with the addition that the area underneath the plotted line is filled. Different variants are available by setting the grouping to “standard”, “stacked” or “percentStacked”; “standard” is the default.
面积图与线性图类似;描绘的线下面进行填充,用面来表示。通过设置grouping不同的值(chart.grouping="standard")绘制不同的面积图,包括”standard”,”stacked”,”percentStacked”,默认为 standard。
from openpyxl import Workbookfrom openpyxl.chart import (AreaChart,Reference,Series,)wb = Workbook()ws = wb.activerows = [['Number', 'Batch 1', 'Batch 2'],[2, 40, 30],[3, 40, 25],[4, 50, 30],[5, 30, 10],[6, 25, 5],[7, 50, 10],]for row in rows: # 为worksheet写入多行数据ws.append(row) # 将list作为一行数据写入worksheet中chart = AreaChart() # 创建 2D图表 对象chart.title = "Area Chart" # 设置图表标题chart.style = 13 # 设置图标风格# chart.grouping="standard" # 设置图表 grouping 类型chart.x_axis.title = 'Test' # 设置x轴名称chart.y_axis.title = 'Percentage' # 设置y轴名称cats = Reference(ws, min_col=1, min_row=1, max_row=7) # 关联分类数据的值data = Reference(ws, min_col=2, min_row=1, max_col=3, max_row=7) # 关联构图数据的值chart.add_data(data, titles_from_data=True) # 为图表添加数据chart.set_categories(cats) # 为图表添加分类ws.add_chart(chart, "A10") # 设置图表位置wb.save("area.xlsx")

3D面积图
创建3D面积图
from openpyxl import Workbookfrom openpyxl.chart import (AreaChart3D,Reference,Series,)wb = Workbook()ws = wb.activerows = [['Number', 'Batch 1', 'Batch 2'],[2, 30, 40],[3, 25, 40],[4 ,30, 50],[5 ,10, 30],[6, 5, 25],[7 ,10, 50],]for row in rows:ws.append(row) # 绘制单元格数据chart = AreaChart3D() # 创建 3D面积图 对象chart.title = "Area Chart"chart.style = 13chart.x_axis.title = 'Test'chart.y_axis.title = 'Percentage'chart.legend = Nonecats = Reference(ws, min_col=1, min_row=1, max_row=7) # 关联分类数据的值data = Reference(ws, min_col=2, min_row=1, max_col=3, max_row=7) #关联构图数据的值chart.add_data(data, titles_from_data=True)chart.set_categories(cats)ws.add_chart(chart, "A10")wb.save("area3D.xlsx")
这样就创建了一个简单的 3D面积图。 面积图的 Z轴 可以用来作为数据说明。

^ <-Previous | Next-> |
