python主流绘图工具:matplotlib ,seaborn,pandas ,openpyxl ,xslwriter

openpyxl :首先说下这个官网的demo,看的有点懵,没有具体说明多个图在一个excel引用不通ws Rererence 只是简单的一个deepcopy 用的一点懵逼,反正我是没看懂,其次多sheet写入也未做拓展,

看了下博客哪些水军一篇粘贴复制毫无新意:

下面以openpyxl 3d bar 柱状图为例:演示效果多sheet 生成柱状图:

官网:https://openpyxl.readthedocs.io/en/latest/charts/bar.html#d-bar-charts

from openpyxl import Workbook
from openpyxl.chart import (
Reference,
Series,
BarChart3D,
) def bar_3d(configurations: dict):
""""
paint 3d bar in the excel ,
configuration={"data":None,"Title":None,"sheet_name":None,"index":None}
data:[
[姓名,column1,column2],
[value_name,value_col1,value_col2],
[value_name2,value_column2,value_column2]
]
"""
wb = Workbook()
for configuration in configurations:
sheet = configuration["sheet_name"]
ws = wb.create_sheet(sheet, index=configuration["index"])
rows = configuration["data"]
rows.insert(0, configuration["axis_x"])
for row in rows:
ws.append(row)
data = Reference(ws, min_col=2, min_row=1, max_col=3, max_row=7)
titles = Reference(ws, min_col=1, min_row=2, max_row=7)
chart = BarChart3D()
chart.title = configuration["Title"]
chart.add_data(data=data, titles_from_data=True)
chart.set_categories(titles)
chart.height=16
chart.width=28
chart.shape="box" ws.add_chart(chart, "E5")
save_path = "test_static.xlsx"
wb.save(save_path)

  解释参数:configurations 是一个存放许多configranition 的列表:每个configration 结构如注释:

configuration={"data":None,"Title":None,"sheet_name":None,"index":None}
data:[ [value_name,value_col1,value_col2],
[value_name2,value_column2,value_column2]
]
data就是要写入的数据包含header 和value,data[0]是表头,data[1:]全部是数据,index代表插入excel的sheet的index也就是第几个sheet,Title是绘制柱状图的title:
chart.height是图表的高度,width是宽度,add_chart 是插入chart 方法“E5"指定在excel插入位置,
rows.insert(0, configuration["axis_x"]) 这里插入是type分类的名称也就是rows.insert(0,[姓名,column1,column2])
,看个实际效果吧这个type就对应周日饱和,和bug提交量两列

多个sheet查看:

第二部分:使用pandas 绘图结合xslwriter:

官网:https://xlsxwriter.readthedocs.io/example_pandas_chart_columns.html

我就直接上代码了数据自己造了个用pandas:

import pandas as pd

def panda_chart(df_list, cols, title_x, title_y):
"""
data of narray
index of data_frame: [0,1,2,3]
cols numbers of static columns
""" writer = pd.ExcelWriter('pandas_chart_columns2.xlsx', engine='xlsxwriter')
for i, df in enumerate(df_list):
# df = pd.DataFrame(data, index=None, columns=["姓名", "饱和度", "人力"])
sheet_name = f'Sheet{i}'
df.to_excel(writer, sheet_name=sheet_name,index=False)
workbook = writer.book
worksheet = writer.sheets[sheet_name]
chart = workbook.add_chart({'type': 'column'})
# set colors for the chart each type .
colors = ['#E41A1C', '#377EB8'] # , '#4DAF4A', '#984EA3', '#FF7F00']
# Configure the series of the chart from the dataframe data.
for col_num in range(1, cols + 1):
chart.add_series({
'name': [f'{sheet_name}', 0, col_num],
'categories': [f'{sheet_name}', 1, 0, 4, 0], # axis_x start row ,start col,end row ,end col
'values': [f'{sheet_name}', 1, col_num, 4, col_num], # axis_y value of
'fill': {'color': colors[col_num - 1]}, # each type color choose
'overlap': -10,
}) # Configure the chart axes.
chart.set_x_axis({'name': f'{title_x}'})
chart.set_y_axis({'name': f'{title_y}', 'major_gridlines': {'visible': False}})
chart.set_size({'width': 900, 'height': 400})
# Insert the chart into the worksheet.
worksheet.insert_chart('H2', chart)
writer.save() if __name__ == '__main__':
data=[("a",2,4),("b",5,7)]
df = pd.DataFrame(data, index=None, columns=["姓名", "饱和度", "人力"])
panda_chart([df],2,"title x","title y")

  


pandas 进行excel绘图的更多相关文章

  1. 深入理解pandas读取excel,txt,csv文件等命令

    pandas读取文件官方提供的文档 在使用pandas读取文件之前,必备的内容,必然属于官方文档,官方文档查阅地址 http://pandas.pydata.org/pandas-docs/versi ...

  2. Python利用pandas处理Excel数据的应用

    Python利用pandas处理Excel数据的应用   最近迷上了高效处理数据的pandas,其实这个是用来做数据分析的,如果你是做大数据分析和测试的,那么这个是非常的有用的!!但是其实我们平时在做 ...

  3. 51-python3 pandas读写excel

    转载自:https://blog.csdn.net/brink_compiling/article/details/76890198?locationNum=7&fps=1 0. 前言Pyth ...

  4. pandas 将excel一列拆分成多列重新保存

    利用pd.read_excel   做到将第二列“EVT-LBL”按“-”分割后重新加三列在df后面 1 读取表格df 2. 分割第二列短横连接的数字,保存到df2---- 参考:str.spilt( ...

  5. 【python基础】利用pandas处理Excel数据

    参考:https://www.cnblogs.com/liulinghua90/p/9935642.html 一.安装第三方库xlrd和pandas 1:pandas依赖处理Excel的xlrd模块, ...

  6. Python 使用Pandas读取Excel的学习笔记

    这里介绍Python中使用Pandas读取Excel的方法 一.软件环境: OS:Win7 64位 Python 3.7 二.文件准备 1.项目结构: 2.在当前实验文件夹下建立一个Source文件夹 ...

  7. 机器学习之数据预处理,Pandas读取excel数据

    Python读写excel的工具库很多,比如最耳熟能详的xlrd.xlwt,xlutils,openpyxl等.其中xlrd和xlwt库通常配合使用,一个用于读,一个用于写excel.xlutils结 ...

  8. pandas read excel文件碰到的一个小问题

    今天利用pandas读取excel时,爆出如下错误: 代码为: import pandas as pd db_eua=pd.read_excel('db_eua.xlsx',sheetname='EU ...

  9. Python用Pandas读写Excel

    Pandas是python的一个数据分析包,纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具.Pandas提供了大量能使我们快速便捷地处理数据的函数和方法. Pandas官方文档 ...

随机推荐

  1. Hackme.inndy -> Onepunch

    Onepunch 这个题的想法必须得称妙了,需要对以往简单的认知进行一定的颠覆.特殊性在于程序的代码段(0x401000)具有写权限 1.通过修改程序代码段控制程序流程 程序中只能对任意一个字节改写一 ...

  2. H5_0013:CSS特色样式集

    按比例变化,同时又限制最大宽高 ".start-wrap {", " width:40%;", " top: 83.21%;", " ...

  3. .Net Core的总结

    一.什么是.NET Core .NET Core是一个开源通用的开发框架,支持跨平台,即支持在Window,macOS,Linux等系统上的开发和部署,并且可以在硬件设备,云服务,和嵌入式/物联网方案 ...

  4. 二叉堆(2)LeftistHeap

    左倾堆,用于堆的快速合并. 规则: ① 节点的键值小于或等于它的左右子节点的键值. ② 节点的左孩子的NPL >= 右孩子的NPL. ③ 节点的NPL = 它的右孩子的NPL + 1. 测试文件 ...

  5. ubuntu 16.04.1上安装并使用nginx

    1.安装 sudo apt-get install nginx 2.这时候应该就已经启动了,跳到步骤4. 通过命令“ps -aux | grep nginx”看下是否启动 3.如果没有启动,可以使用命 ...

  6. python 方法和函数

    代码 def func(): pass class Foo(object): def func(self): pass # 执行方式一 # obj = Foo() # obj.func() # 方法 ...

  7. SQLyog怎么导入mysql数据库

    参考链接:https://jingyan.baidu.com/article/647f0115c5ad9f7f2148a8c6.html

  8. vue.js 的cdn 链接的引用地址

    引用地址有两种一种完整版,一种压缩版效果是一样的 https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js https://cdn.bootcss.com ...

  9. Wannafly Camp 2020 Day 2F 采蘑菇的克拉莉丝 - 树链剖分

    如果暴力维护,每次询问时需要对所有孩子做计算 考虑通过树剖来平衡修改与询问的时间,询问时计算重链和父树,轻链的贡献预先维护好,修改时则需要修改可能影响的轻链贡献,因为某个点到根的路径上轻重交替只有 \ ...

  10. 安装python3.7.4时报错:Service Pack 1 is required to continue installation

    python3.7.4安装失败:Service Pack 1 is required to continue installation 解决办法: 点击报错页面中的“log file”,日志最后一行显 ...