偏移 柱状图_柱状图写入表格
发布日期:2021-06-24 13:32:46 浏览次数:2 分类:技术文章

本文共 1908 字,大约阅读时间需要 6 分钟。

#!/usr/bin/env Python3# -*- coding: utf-8 -*-# @Software: PyCharm# @virtualenv:workon# @contact: 1040691703@qq.com# @Desc:Code descripton__author__ = '未昔/AngelFate'__date__ = '2020/4/28 12:49'# -*- coding:utf-8 -*-import xlsxwriter# 创建一个excelworkbook = xlsxwriter.Workbook("chart_column.xlsx")# 创建一个sheetworksheet = workbook.add_worksheet()# worksheet = workbook.add_worksheet("bug_analysis")# 自定义样式,加粗bold = workbook.add_format({'bold': 1})# --------1、准备数据并写入excel---------------# 向excel中写入数据,建立图标时要用到headings = ['Number', 'testA', 'testB']data = [    ['2020-4-21', '2020-4-22', '2020-4-23', '2020-4-24', '2020-4-25', '2020-4-26'],    [50, 40, 50, 60, 70, 50],    [30, 60, 60, 50, 40, 30],]# 写入表头worksheet.write_row('A1', headings, bold)# 写入数据worksheet.write_column('A2', data[0])worksheet.write_column('B2', data[1])worksheet.write_column('C2', data[2])# --------2、生成图表并插入到excel---------------# 创建一个柱状图(column chart)chart_col = workbook.add_chart({'type': 'column'})# 配置第一个系列数据chart_col.add_series({    # 这里的sheet1是默认的值,因为我们在新建sheet时没有指定sheet名    # 如果我们新建sheet时设置了sheet名,这里就要设置成相应的值    'name': '=Sheet1!$B$1',    'categories': '=Sheet1!$A$2:$A$7',    'values':   '=Sheet1!$B$2:$B$7',    'line': {'color': 'red'},})# 配置第二个系列数据(用了另一种语法)chart_col.add_series({    'name': '=Sheet1!$C$1',    'categories':  '=Sheet1!$A$2:$A$7',    'values':   '=Sheet1!$C$2:$C$7',    'line': {'color': 'yellow'},})# 配置第二个系列数据(用了另一种语法)# chart_col.add_series({#     'name': ['Sheet1', 0, 2],#     'categories': ['Sheet1', 1, 0, 6, 0],#     'values': ['Sheet1', 1, 2, 6, 2],#     'line': {'color': 'yellow'},# })# 设置图表的title 和 x,y轴信息chart_col.set_title({'name': 'The xxx site Bug Analysis'})chart_col.set_x_axis({'name': 'Test number'})chart_col.set_y_axis({'name':  'Sample length (mm)'})# 设置图表的风格chart_col.set_style(1)# 把图表插入到worksheet以及偏移worksheet.insert_chart('A10', chart_col, {'x_offset': 25, 'y_offset': 10})workbook.close()
bf0140f603acf2d2ff5dd24fce6a5df0.png

转载地址:https://blog.csdn.net/weixin_33212263/article/details/112580997 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:怎么自动缩进_很多人都知道「首行缩进」,其实「缩进」还有7种用法,非常实用...
下一篇:小程序制作预算_小程序开发制作价格

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月04日 06时05分48秒