Python学习pygal绘制线图代码分享
作者:chipsKe 时间:2022-12-02 10:51:48
pygal的安装大家可以参阅:pip和pygal的安装实例教程
线图:
import pygal
line_chart = pygal.Line()
line_chart.title = 'Browser usage evolution (in %)'
line_chart.x_labels = map(str, range(2002, 2013))
line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])
line_chart.render_to_file('bar_chart.svg')
水平线图:
line_chart = pygal.HorizontalLine()
line_chart.title = 'Browser usage evolution (in %)'
line_chart.x_labels = map(str, range(2002, 2013))
line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])
line_chart.range = [0, 100]
line_chart.render_to_file('bar_chart.svg')
叠加测线:
line_chart = pygal.StackedLine(fill=True)
line_chart.title = 'Browser usage evolution (in %)'
line_chart.x_labels = map(str, range(2002, 2013))
line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])
line_chart.render_to_file('bar_chart.svg')
对于时间相关的图,只需格式化标签或使用xy图表的一个变体:
from datetime import datetime
date_chart = pygal.Line(x_label_rotation=20)
date_chart.x_labels = map(lambda d: d.strftime('%Y-%m-%d'), [
datetime(2013, 1, 2),
datetime(2013, 1, 12),
datetime(2013, 2, 2),
datetime(2013, 2, 22)])
date_chart.add("Visits", [300, 412, 823, 672])
date_chart.render_to_file('bar_chart.svg')
来源:http://www.cnblogs.com/keqipu/p/7281987.html
标签:python,pygal
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
OpenCV3.3+Python3.6实现图片高斯模糊
2023-12-29 23:09:48
![](https://img.aspxhome.com/file/2023/8/124418_0s.jpg)
如何使用Django默认的Auth权限管理系统
2022-11-29 04:09:40
![](https://img.aspxhome.com/file/2023/0/134880_0s.png)
asp常用数据库连接方法和技巧
2010-05-27 12:28:00
Python干货:分享Python绘制六种可视化图表
2023-07-10 10:01:03
![](https://img.aspxhome.com/file/2023/9/66369_0s.png)
Python生成随机MAC地址
2023-04-09 18:05:57
vue中的v-show,v-if,v-bind的使用示例详解
2024-05-28 15:48:07
pygame实现俄罗斯方块游戏(基础篇3)
2022-10-10 10:45:54
![](https://img.aspxhome.com/file/2023/9/69529_0s.jpg)
Python机器学习应用之朴素贝叶斯篇
2024-01-02 23:11:15
![](https://img.aspxhome.com/file/2023/0/101030_0s.png)
处理HTML代码的若干函数
2009-08-21 13:21:00
Python面试题之统计哈希列表中最多元素
2023-06-26 20:24:49
Python中装饰器高级用法详解
2023-09-30 09:46:42
python+pytest自动化测试函数测试类测试方法的封装
2021-12-26 21:03:14
![](https://img.aspxhome.com/file/2023/7/105257_0s.png)
简单聊聊Python中的鸭子类型和猴子补丁
2022-06-17 00:32:58
Sublime Text 配置 Python 环境的问题及解决方案
2022-04-26 15:14:41
为ABP框架配置数据库
2024-01-19 21:52:05
MySQL Group By用法
2012-01-05 19:05:14
MySQL外键创建失败1005原因汇总
2024-01-20 00:16:58
Oracle 9i轻松取得建表和索引的DDL语句
2010-07-16 13:09:00
Python中的基本数据类型介绍
2023-07-21 22:26:26
![](https://img.aspxhome.com/file/2023/4/120314_0s.png)
SELECT...INTO的具体用法
2024-01-29 02:20:43