本文繼續採用PyEcharts v1.x版本進行繪製地圖。
注:PyEcharts分爲 v0.5.x 和 v1.x 兩個大版本,v0.5.x 和 v1.x 間不兼容,v0.5.x是基於Python2.7+、3.4+版本開發的,而v1.x是一個全新的版本,它是基於Python3.6+版本開發的,另外經PyEcharts開發團隊決定,0.5.x 版本將再也不進行維護。html
繪製的柱圖效果是這樣的:
沒有安裝PyEcharts的,先安裝PyEcharts:python
# 安裝pyecharts模塊,直接安裝就是最新的版本 pip install pyecharts
安裝好PyEcharts以後,就能夠將須要使用的模塊進行導入:echarts
#導入須要使用的模塊 from pyecharts import options as opts from pyecharts.charts import Bar import pandas as pd
導入數據:ide
data = pd.read_excel('D:/python/xgyq.xlsx',sheet_name='1')#按新增字段進行降序data = data.sort_values(by=['新增'],ascending=[False])
長按識別下方二維碼,並關注公衆號
回覆「DTX」獲取案例數據學習
接下來就能夠繪製柱形圖了:3d
c = ( #建立柱圖對象,並設置大小,也能夠不設置,直接使用默認大小便可 Bar(init_opts=opts.InitOpts(width="800px", height="400px")) #設置X軸數據系列,只取前10個數據,並轉爲列表格式 .add_xaxis(data.省份[:10].tolist()) #設置Y軸數據系列及顯示顏色,只取前10個數據,並轉爲列表格式 .add_yaxis("", data.新增[:10].tolist()) # 設置圖表標題及位置 .set_global_opts(title_opts=opts.TitleOpts(title="新增TOP10",pos_left="center")) #經過render()方法將柱圖渲染爲html .render("柱形圖.html") )
c = ( Bar(init_opts=opts.InitOpts(width="800px", height="400px")) .add_xaxis(data.省份[:10].tolist()) .add_yaxis("累計", data.確診人數[:10].tolist()) .add_yaxis("新增", data.新增[:10].tolist()) .set_global_opts(title_opts=opts.TitleOpts(title="TOP10")) .render("柱形圖.html") )
繪製的多數據系列柱形圖效果是這樣的:excel
c = ( Bar(init_opts=opts.InitOpts(width="800px", height="400px")) .add_xaxis(data.省份[:10].tolist()) #設置Y軸數據系列及顯示顏色 .add_yaxis("", data.新增[:10].tolist(),color='#FF1493') .set_global_opts(title_opts=opts.TitleOpts(title="新增TOP10",pos_left="center")) .render("柱形圖.html") )
是否是so easy 呢?code
長按識別下方二維碼,並關注公衆號htm