前言
本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,著作權歸原作者所有,如有問題請及時聯系我們以作處理,
沒有安裝PyEcharts的,先安裝PyEcharts:
data = https://www.cnblogs.com/hhh188764/p/pd.read_excel('D:/python/xgyq.xlsx',sheet_name='1')#按新增欄位進行降序
data = https://www.cnblogs.com/hhh188764/p/data.sort_values(by=['新增'],ascending=[False])
安裝好PyEcharts之后,就可以將需要使用的模塊進行匯入:
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"))
#設定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"))
#設定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")
)
繪制的多資料系列柱形圖效果是這樣的:
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")
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/105987.html
標籤:Python
上一篇:OD機試題
