python xlsxwriter 画图_Python-使用XlsxWriter模块用图案填充列绘制Excel图表
图表至少由一系列一个或多个数据点组成。系列本身由对单元格范围的引用组成。为了在Excel工作表上绘制图表,首先,创建特定图表类型的图表对象(即柱形图等)。创建图表对象后,在其中插入数据,最后,将该图表对象添加到图纸对象中。
示例# import xlsxwriter module
import xlsxwriter
#Workbook()takes one,non-optional,argument which is the filename
#that we want to create.
workbook = xlsxwriter.Workbook('chart_pattern.xlsx')
# The workbook object is then used to add new worksheet via the #add_worksheet() method.
worksheet = workbook.add_worksheet()
# Create a new Format object to formats cells in worksheets using #add_format() method .
# here we create bold format object .
bold = workbook.add_format({'bold': 1})
# Add the worksheet data that the charts will refer to.
headings = ['Shingle', 'Brick']
data = [
[105, 150, 130, 90 ],
[50, 120, 100, 110],
]
# Write a row of data starting from 'A1' with bold format .
worksheet.write_row('A1', headings, bold)
# Write a column of data starting from 'A2', 'B2' respectively .
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
# Create a chart object that can be added to a worksheet using #add_chart() method.
# here we create a column chart object
chart = workbook.add_chart({'type': 'column'})
# Add a data series with pattern to a chart using add_series method. # The gap is used to make the patterns more visible.
# Configure the first series.= Sheet1 !$A$1 is equivalent to ['Sheet1', 0, 0].
# note : spaces is not inserted in b/w = and Sheet1, Sheet1 and !
# if space is inserted it throws warning.
chart.add_series({
'name': '= Sheet1 !$A$1',
'values': '= Sheet1 !$A$2:$A$5',
'pattern': {
'pattern': 'shingle',
'fg_color': '# 804000',
'bg_color': '# c68c53'
},
'border': {'color': '# 804000'},
'gap': 70,
})
# Configure a second series.
chart.add_series({
'name': '= Sheet1 !$B$1',
'values': '= Sheet1 !$B$2:$B$5',
'pattern': {
'pattern': 'horizontal_brick',
'fg_color': '# b30000',
'bg_color': '# ff6666'
},
'border': {'color': '# b30000'},
})
# Add a chart title
chart.set_title ({'name': 'Cladding types'})
# Add x-axis label
chart.set_x_axis({'name': 'Region'})
# Add y-axis label
chart.set_y_axis({'name': 'Number of houses'})
# add chart to the worksheet with given offset values at the top-#left corner of a chart is anchored to cell D2 .
worksheet.insert_chart('D2', chart, {'x_offset': 25, 'y_offset': 10})
# Finally, close the Excel file via the close() method.
workbook.close()
python xlsxwriter 画图_Python-使用XlsxWriter模块用图案填充列绘制Excel图表相关推荐
- c调用python第三方库_Python使用ctypes模块调用DLL函数之C语言数组与numpy数组传递...
在Python语言中,可以使用ctypes模块调用其它如C++语言编写的动态链接库DLL文件中的函数,在提高软件运行效率的同时,也可以充分利用目前市面上各种第三方的DLL库函数,以扩充Python软件 ...
- python psycopg2使用_Python中用psycopg2模块操作PostgreSQL方法
其实在Python中可以用来连接PostgreSQL的模块很多,这里比较推荐psycopg2.psycopg2安装起来非常的简单(pip install psycopg2),这里主要重点介绍下如何使用 ...
- python 主线程_Python threading多线程模块
Python是支持使用多线程的,程序代码可以在一个进程空间中操作管理多个执行的线程,python模块下载时要记得,这个库叫做 threading. 一.threading模块简介 在Python多线程 ...
- python xlsxwriter 画图_Python XlsxWriter模块Chart类用法实例分析
本文实例讲述了Python XlsxWriter模块Chart类用法.共享给大家供大家参考,详细如下: 一 点睛 Chart类是XlsxWriter模块中图表组件的基类,支持的图表类型包括面积.条形图 ...
- python快速画图_python画图教程|无所不能的python编程是怎么快速画图的呢
python怎么在屏幕上画图 用库matplot,用起来很方便 怎么用python绘图 请查python的第三方库matplotlab,这个里许多类似matlib(http://matplotlib. ...
- python requests 示例_python的requests模块实现登陆示例
51cto用python的requests模块实现登陆示例代码如下: -- coding:utf-8 -- import requests import re client = requests.se ...
- python schedule多线程_Python定时任务sched模块用法示例
本文实例讲述了Python定时任务sched模块用法.分享给大家供大家参考,具体如下: 通过sched模块可以实现通过自定义时间,自定义函数,自定义优先级来执行函数. 范例一 import time ...
- python xlrd课程_python中xlrd模块的使用详解
一.xlrd的安装 打开cmd输入pip install xlrd安装完成即可 二.xlrd模块的使用 下面以这个工作簿为例 1.导入模块 import xlrd 2.打开工作薄 # filename ...
- python time 语句_python的time模块总结
python的time模块与random模块 目录 time模块 time模块 三种时间表示 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp) : 通常来说,时间戳表示的是 ...
最新文章
- SQL Server-表表达式基础
- 【收藏】spring boot+websocket+echarts 后台推送数据用echarts展示
- 用BlockingQueue实现生产者与消费者问题
- codevs 1230【pb_ds】
- 用户体验数据分析 书单_如何使用数据改善用户体验设计
- network---written test
- YUV格式文件转RGB格式
- 第 39 级台阶 蓝桥杯
- docx文档怎么排列图片_PDF怎么转Word?这几款软件满足你的要求
- android提醒设置,如何在Android中设置提醒?
- multisim 10 小知识
- 华为手机计算机快捷设置密码,华为手机首次重启绘制图案密码后让输入解锁密码。我没有设置呀?怎么办...
- 计算机电脑密码设置程序,如何设置计算机开机密码和屏幕保护程序密码
- SIM800系列模块GSM/GPRS建立TCP连接到远端服务器过程——新浪博客迁移
- 视频格式怎么改为mp4?有什么好用的视频格式转换软件
- windows server 2012 NIC组合---概念
- 6-3 每个单词的首字母改为大写 (10 分)
- 【CTS2019】氪金手游(动态规划)
- TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.2 以太网与 IEEE 802 LAN/MAN 标准 / 3.2.2 以太网帧格式
- 8月起,《PMBOK®指南(第七版)》将被采用,考PMP的注意了!
热门文章
- 爱默生----生活的准则
- c6.nv9.info.php,com.apk 0% 的杀毒软件(0/32) 报告发现病毒 - VirSCAN.org-多引擎在线病毒扫描网 v1.02,当前支持 47 款杀毒引擎...
- 英文论文写作中的Annotated Bibliography分析
- conda的基本操作(命令行终端)
- tchar与char不兼容_TCHAR与char的转换 | 学步园
- python word中表格字体设置_利用Python-docx 读写 Word 文档中的正文、表格、段落、字体样式等...
- 【无标题】2023第十五届上海国际智慧城市、物联网、大数据博览会
- 11 个对开发有帮助的 JS 技巧,进收藏夹当小词典吧!
- 大数据分析完28个省会城市后,我们发现存在感最低的省会城市竟是......
- USB音频芯片/TYPEC音视频处理芯片方案选型表