手把手教你用Pyecharts繪制這3種超經(jīng)典圖表

導(dǎo)讀:Pyecharts繪制上下組合圖、左右組合圖、一軸多圖,超經(jīng)典!
作者:黃偉呢
來(lái)源:數(shù)據(jù)分析與統(tǒng)計(jì)學(xué)之美(ID:huang_superme)
01?上下組合
from?pyecharts.charts?import?Bar,?Line,?Grid
from?pyecharts?import?options
#?1、準(zhǔn)備數(shù)據(jù)
country?=?['巴西',?'俄羅斯',?'印度',?'英國(guó)',?'西班牙',?'伊朗',?'德國(guó)',?'土耳其',?'法國(guó)']
quezheng?=?[923189,553301,354065,298136,244328,192439,188252,181298,157716]
siwang?=?[45241,7478,11903,41969,27136,9065,8802,4842,29547]
#?2、繪制柱形圖
bar?=?(
????Bar()
????.add_xaxis(country)
????.add_yaxis("確診人數(shù)",?quezheng)
????.add_yaxis("死亡人數(shù)",?siwang)
????.set_global_opts(title_opts=options.TitleOpts(title="我是標(biāo)題",?subtitle="我是副標(biāo)題"))
)
#?3、繪制線圖
line?=?(
????Line()
????.add_xaxis(country)
????.add_yaxis("quzheng人數(shù)",?quezheng)
????.add_yaxis("siwang人數(shù)",?siwang)
????.set_global_opts(legend_opts=opts.LegendOpts(pos_bottom="45%"))
)
#?4、創(chuàng)建組合圖
(Grid(init_opts=opts.InitOpts(width='750px',?height='350px'))
?.add(bar,grid_opts=opts.GridOpts(pos_bottom="60%"))
?.add(line,grid_opts=opts.GridOpts(pos_top="60%"))
).render_notebook()結(jié)果如下:

02 左右組合
from?pyecharts.charts?import?Bar,?Line,?Grid
from?pyecharts?import?options
#?1、準(zhǔn)備數(shù)據(jù)
country?=?['巴西',?'俄羅斯',?'印度',?'英國(guó)',?'西班牙',?'伊朗',?'德國(guó)',?'土耳其',?'法國(guó)']
quezheng?=?[923189,553301,354065,298136,244328,192439,188252,181298,157716]
siwang?=?[45241,7478,11903,41969,27136,9065,8802,4842,29547]
#?2、繪制柱形圖
bar?=?(
????Bar()
????.add_xaxis(country)
????.add_yaxis("確診人數(shù)",?quezheng,?label_opts=opts.LabelOpts(is_show=False))
????.add_yaxis("死亡人數(shù)",?siwang,?label_opts=opts.LabelOpts(is_show=False))
????.set_global_opts(title_opts=options.TitleOpts(title="我是標(biāo)題",?subtitle="我是副標(biāo)題"),
?????????????????????legend_opts=opts.LegendOpts(pos_right="20%"))
)
#?3、繪制線圖
line?=?(
????Line()
????.add_xaxis(country)
????.add_yaxis("quzheng人數(shù)",?quezheng,?label_opts=opts.LabelOpts(is_show=False))
????.add_yaxis("siwang人數(shù)",?siwang,?label_opts=opts.LabelOpts(is_show=False))
????.set_global_opts(legend_opts=opts.LegendOpts(pos_left="20%"))
)
#?4、創(chuàng)建組合圖
(Grid(init_opts=opts.InitOpts(width='750px',?height='350px'))
?.add(bar,grid_opts=opts.GridOpts(pos_left="55%"))
?.add(line,grid_opts=opts.GridOpts(pos_right="55%"))
).render_notebook()結(jié)果如下:

03 一軸多圖
from?pyecharts.charts?import?Bar,?Line,?Grid
from?pyecharts?import?options
#?1、準(zhǔn)備數(shù)據(jù)
from?pyecharts.charts?import?Bar,?Line,?Grid
from?pyecharts?import?options
#?1、準(zhǔn)備數(shù)據(jù)
country?=?['巴西',?'俄羅斯',?'印度',?'英國(guó)',?'西班牙',?'伊朗',?'德國(guó)',?'土耳其',?'法國(guó)']
quezheng?=?[923189,553301,354065,298136,244328,192439,188252,181298,157716]
siwang?=?[45241,7478,11903,41969,27136,9065,8802,4842,29547]
#?2、繪制柱形圖
bar?=?(
????Bar(init_opts=opts.InitOpts(width='750px',?height='350px'))
????.add_xaxis(country)
????.add_yaxis("確診人數(shù)",?quezheng)
????.add_yaxis("死亡人數(shù)",?siwang)
????.set_global_opts(title_opts=options.TitleOpts(title="我是標(biāo)題",?subtitle="我是副標(biāo)題"))
)
#?3、繪制線圖
line?=?(
????Line()
????.add_xaxis(country)
????.add_yaxis("確診人數(shù)",?quezheng,?label_opts=opts.LabelOpts(is_show=False))
????.add_yaxis("死亡人數(shù)",?siwang,?label_opts=opts.LabelOpts(is_show=False))
)
#?4、創(chuàng)建組合圖
bar.overlap(line).render_notebook()結(jié)果如下:



延伸閱讀《ECharts數(shù)據(jù)可視化》
干貨直達(dá)??
評(píng)論
圖片
表情
