国产探花免费观看_亚洲丰满少妇自慰呻吟_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繪制線圖代碼分享的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題。如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 慈溪市| 平顺县| 兰溪市| 邹平县| 太仆寺旗| 河东区| 普兰店市| 静乐县| 怀柔区| 麟游县| 齐齐哈尔市| 阳泉市| 益阳市| 陕西省| 右玉县| 明水县| 普定县| 平利县| 庆城县| 徐汇区| 拜城县| 永仁县| 铜川市| 武夷山市| 胶州市| 安泽县| 抚州市| 周至县| 莱西市| 泽库县| 江都市| 盐亭县| 嘉义县| 高唐县| 姚安县| 临朐县| 西藏| 扶绥县| 宁德市| 吉安市| 东丰县|