国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python學習pygal繪制線圖代碼分享

2020-02-16 11:00:27
字體:
來源:轉載
供稿:網友

pygal的安裝大家可以參閱:pip和pygal的安裝實例教程

線圖:

import pygalline_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 datetimedate_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')

總結

以上就是本文關于Python學習pygal繪制線圖代碼分享的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題。如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵溪市| 荣昌县| 龙州县| 陆丰市| 景谷| 永丰县| 梓潼县| 滨海县| 山阴县| 大姚县| 饶阳县| 大埔区| 洞头县| 荣昌县| 南江县| 遵义县| 施甸县| 海晏县| 临漳县| 观塘区| 双辽市| 白朗县| 开远市| 遂川县| 武邑县| 聂荣县| 益阳市| 武乡县| 宁陕县| 三明市| 靖远县| 资中县| 皮山县| 浦城县| 涪陵区| 巩义市| 余姚市| 疏勒县| 宜宾县| 岢岚县| 北川|