最近發(fā)現(xiàn)一個(gè)顏值爆表的數(shù)據(jù)可視化庫宾符,
簡單易上手的同時(shí)功能非常強(qiáng)大酿秸,
以下是柱狀圖、折線圖魏烫、環(huán)形餅圖的基本示例辣苏,
跟網(wǎng)上其他示例不同的是,我用了一些個(gè)性化表達(dá)的通用配置哄褒,
例如x軸標(biāo)簽設(shè)置旋轉(zhuǎn)角度稀蟋、折線圖平滑曲線、圖例顯示或隱藏呐赡、自定義顯示系列名等退客。
使用Jupyter Notebook編程工具,
本文源代碼地址:https://download.csdn.net/download/s34855/10855445
pyecharts詳細(xì)的使用文檔地址:http://pyecharts.org/#/zh-cn/
柱狀圖
from pyecharts import Bar # 導(dǎo)入柱狀圖-Bar
# 橫縱坐標(biāo)
columns = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
# 設(shè)置數(shù)據(jù)
data1 = [200, 500, 80, 230, 300, 700, 200, 100, 500, 600, 700, 300]
data2 = [250, 500, 900, 260, 280, 400, 180, 150, 500, 220, 300, 200]
# 設(shè)置柱狀圖的主標(biāo)題與副標(biāo)題
bar = Bar("柱狀圖", "年收入與支出")
# 添加柱狀圖的數(shù)據(jù)及配置項(xiàng)
# mark_point链嘀,標(biāo)記點(diǎn)萌狂,默認(rèn)有'min', 'max', 'average'可選。表達(dá)最值
# legend_orient怀泊,圖例列表的布局朝向茫藏,有'horizontal', 'vertical'可選,默認(rèn) -> 'horizontal'
# legend_pos霹琼,圖例組件離容器左側(cè)的距離务傲,有'left', 'center', 'right'可選凉当,也可以為百分?jǐn)?shù),如"%60"售葡,默認(rèn) -> 'center'
bar.add("收入", columns, data1, mark_line=["average"], mark_point=["max", "min"],legend_orient='vertical',legend_pos='right')
bar.add("支出", columns, data2, mark_line=["average"], mark_point=["max", "min"],legend_orient='vertical',legend_pos='right')
# 生成本地文件(默認(rèn)為.html文件看杭,根目錄)
bar.render()
bar # 在jupyter notebook顯示圖表
柱狀圖Bar.png
折線圖
from pyecharts import Line # 導(dǎo)入折線圖-Line
line = Line("折線圖", "每周銷售量", width=1200, height=400)
attr = ['8.3-8.9','8.10-8.16','8.16-8.22','8.23-8.29','8.30-9.5','9.6-9.12','9.13-9.19','9.20-9.26']
data = [12000,22000,21000,29000,35000,26000,26000,23000]
# mark_line=["average"]趨勢線
# is_label_show=True顯示數(shù)據(jù)標(biāo)簽
# x軸標(biāo)簽設(shè)置旋轉(zhuǎn)角度xaxis_rotate
# legend_pos,圖例組件離容器左側(cè)的距離,有'left', 'center', 'right'可選
# is_smooth -> bool,是否平滑曲線顯示天通,默認(rèn)為 False
line.add("銷售量",attr,data, is_label_show=True,legend_orient='vertical',legend_pos='center', is_smooth=True, xaxis_rotate='30')
# 指定生成html文件
line.render(r"C:\Programming\Python3\Test\每周銷售量折線圖.html")
line # 在jupyter notebook顯示圖表
折線圖Line.png
環(huán)形餅圖
from pyecharts import Pie # 導(dǎo)入餅圖-Pie
attr = ["蔬菜","水果","肉品","零食","飲料"]
data = [14,10,13,309,200]
pie = Pie("環(huán)形餅圖", "商品種類", title_pos='center_left')
# legend_orient='vertical',legend_pos='left'泊窘,圖例方向和位置
# is_legend_show=False,圖例顯示隱藏
# label_formatter='像寒:{c}, 9cixle7%'烘豹,自定義顯示系列名、數(shù)據(jù)名诺祸、數(shù)據(jù)值等
pie.add("",attr,data,radius=[40,75],label_tet_color=None,is_label_show=True, label_formatter='携悯:{c}, msde1z7%',legend_orient='vertical',legend_pos='right')
pie.render(r"C:\Programming\Python3\Test\商品種類(環(huán)形餅圖).html")
pie
環(huán)形餅圖Pie.png