Python第三方库之openpyxl(4)
Python第三方库之openpyxl(4)
2D柱状图
在柱状图中,值被绘制成水平条或竖列。
垂直、水平和堆叠柱状图。
注意:以下设置影响不同的图表类型
1.在垂直和水平条形图之间切换,分别设置为col或bar
2.当使用堆叠图表时,overlap需要设置为100
3.如果条是水平的,x轴和y轴要反转
from openpyxl import Workbook
from openpyxl.chart import BarChart, Series, Reference wb = Workbook(write_only=True)
ws = wb.create_sheet() rows = [
('Number', 'Batch 1', 'Batch 2'),
(2, 10, 30),
(3, 40, 60),
(4, 50, 70),
(5, 20, 10),
(6, 10, 40),
(7, 50, 30),
] for row in rows:
ws.append(row) chart1 = BarChart()
chart1.type = "col"
chart1.style = 10
chart1.title = "Bar Chart"
chart1.y_axis.title = 'Test number'
chart1.x_axis.title = 'Sample length (mm)' data = Reference(ws, min_col=2, min_row=1, max_row=7, max_col=3)
cats = Reference(ws, min_col=1, min_row=2, max_row=7)
chart1.add_data(data, titles_from_data=True)
chart1.set_categories(cats)
chart1.shape = 4
ws.add_chart(chart1, "A10") from copy import deepcopy chart2 = deepcopy(chart1)
chart2.style = 11
chart2.type = "bar"
chart2.title = "Horizontal Bar Chart" ws.add_chart(chart2, "G10") chart3 = deepcopy(chart1)
chart3.type = "col"
chart3.style = 12
chart3.grouping = "stacked"
chart3.overlap = 100
chart3.title = 'Stacked Chart' ws.add_chart(chart3, "A27") chart4 = deepcopy(chart1)
chart4.type = "bar"
chart4.style = 13
chart4.grouping = "percentStacked"
chart4.overlap = 100
chart4.title = 'Percent Stacked Chart' ws.add_chart(chart4, "G27") wb.save("bar.xlsx")
运行结果
3D柱状图
from openpyxl import Workbook
from openpyxl.chart import (
Reference,
Series,
BarChart3D,
) wb = Workbook()
ws = wb.active rows = [
(None, 2013, 2014),
("Apples", 5, 4),
("Oranges", 6, 2),
("Pears", 8, 3)
] for row in rows:
ws.append(row) data = Reference(ws, min_col=2, min_row=1, max_col=3, max_row=4)
titles = Reference(ws, min_col=1, min_row=2, max_row=4)
chart = BarChart3D()
chart.title = "3D Bar Chart"
chart.add_data(data=data, titles_from_data=True)
chart.set_categories(titles) ws.add_chart(chart, "E5")
wb.save("bar3d.xlsx")
运行结果
Python第三方库之openpyxl(4)的更多相关文章
- Python第三方库之openpyxl(3)
Python第三方库之openpyxl(3) 区域图 区域图类似于折线图,绘图线下面的区域会被填充,通过将分组设置为“standard”.“stacked”或“percentStacked”,可以获得 ...
- Python第三方库之openpyxl(12)
Python第三方库之openpyxl(12) 地面天气图 在工作表上的列或行中安排的数据可以在一个表中绘制.当您想要在两组数据之间找到最佳组合时,一个表面图表是有用的.正如在地形图中一样,颜色和图案 ...
- Python第三方库之openpyxl(11)
Python第三方库之openpyxl(11) Stock Charts(股票图) 在工作表上按特定顺序排列的列或行中的数据可以在股票图表中绘制.正如其名称所暗示的,股票图表通常被用来说明股价的波动. ...
- Python第三方库之openpyxl(10)
Python第三方库之openpyxl(10) 雷达图 在工作表上的列或行中排列的数据可以在雷达图中绘制.雷达图比较多个数据系列的总值.它实际上是一个圆形x轴上的面积图的投影.有两种类型的雷达图:st ...
- Python第三方库之openpyxl(9)
Python第三方库之openpyxl(9) 油炸圈饼图 甜甜圈图表与饼图相似,只是他们用的是环而不是圆.他们还可以将几个系列的数据绘制成同心环 from openpyxl import Workbo ...
- Python第三方库之openpyxl(8)
Python第三方库之openpyxl(8) 饼图 饼图将数据绘制成一个圆片,每个片代表整体的百分比.切片是按顺时针方向绘制的,0在圆的顶部.饼图只能取一组数据.该图表的标题将默认为该系列的标题. 2 ...
- Python第三方库之openpyxl(7)
Python第三方库之openpyxl(7) 散点图 散点或xy图表类似于一些折线图.主要的区别在于,一个系列的值被绘制在另一个值上.当值未排序时,这是有用的. from openpyxl impor ...
- Python第三方库之openpyxl(6)
Python第三方库之openpyxl(6) 折线图 折线图允许在固定轴上绘制数据,它们类似于散列图,主要的区别在于,在折线图中,每个数据序列都是根据相同的值绘制的,不同的轴可以用于辅助轴,与条形图类 ...
- Python第三方库之openpyxl(5)
Python第三方库之openpyxl(5) 气泡图 气泡图类似于散点图,但使用第三个维度来确定气泡的大小,图表可以包括多个项目 from openpyxl import Workbook from ...
随机推荐
- CentOS7.2 安装iptables
1 先检查是否安装了iptables: service iptables status iptables -L ls /etc/sysconfig/ 综上:命令报错,且 iptables不存在,那 ...
- this详解,对执行上下文说 Yes
this 指向多变,很多隐蔽的 bug 都缘于它.与此同时,this 强大灵活,如果能熟练驾驭,就会写出更简洁.优雅的代码. 社区上对于 this 的讲解虽然不少,但缺乏统一梳理. this 相关知识 ...
- texlive安装
本人电脑系统win8.1,安装texlive2016的时候报错"Can't spawn "cmd.exe": No such file or directory at.. ...
- pyhton中的__new__和__init__
首先__new__() 函数只能用于从object继承的新式类:其次,object将__new__()方法定义为静态方法,并且至少需要传递一个参数cls,cls表示需要实例化的类,此参数在实例化时由P ...
- Android学习总结(十四) ———— ListView Item多布局的实现
一.基本概念 实现一个Item的多布局.像我们经常在用的各种即时通讯工具,QQ.微信等,假设他们的会话界面是ListView实现的,那么ListView就有多种Item布局,要实现ListView里面 ...
- iphone开发设置默认字体
It seems to be possible in iOS 5 using the UIAppearance proxy. [[UILabel appearance] setFont:[UIFont ...
- js 控制台输出
var a = 'string'; var b = 123; console.log("The %s jumped over %d tall buildings", a, b); ...
- python 实例方法,类方法,静态方法,普通函数
python中有实例方法,类方法,静态方法,普通函数 类方法需要@ classmethod 修饰并且有个隐藏参数 cls,实例方法必须有个参数 self, 静态方法必须有 @staticmethod修 ...
- Java中集合类
一.Collection Collection 接口用于表示任何对象或元素组.想要尽可能以常规方式处理一组元素时,就使用这一接口.Collection 在前面的大图也可以看出,它是List 和 Set ...
- bootstrap下拉菜单(Dropdowns)
本章将重点讲解bootstrap下拉菜单(Dropdowns),下拉菜单是可切换的,是以列表格式显示链接的上下文菜单. <!DOCTYPE html><html><hea ...