吊打Pyecharts,又一個(gè)Python繪圖庫!

導(dǎo)讀:最近看了一篇Python 可視化庫PyG2Plot的文章,可惜只是簡(jiǎn)單介紹,并且只有一個(gè)簡(jiǎn)陋的官方示例。

?? PyG2Plot 是@AntV/G2Plot 在 Python3 上的封裝。G2Plot 是一套簡(jiǎn)單、易用、并具備一定擴(kuò)展能力和組合能力的統(tǒng)計(jì)圖表庫,基于圖形語法理論搭建而成。



pip?install?pyg2plotPlot
Plot(plot_type: str): 獲取?Plot?對(duì)應(yīng)的類實(shí)例。 plot.set_options(options: object): 給圖表實(shí)例設(shè)置一個(gè) G2Plot 圖形的配置。 plot.render(path, env, **kwargs): 渲染出一個(gè) HTML 文件,同時(shí)可以傳入文件的路徑,以及 jinja2 env 和 kwargs 參數(shù)。 plot.render_notebook(env, **kwargs): 將圖形渲染到 jupyter 的預(yù)覽。
from?pyg2plot?import?Plotscatter?=?Plot("Scatter")import?requests
#請(qǐng)求地址
url?=?"https://gw.alipayobjects.com/os/bmw-prod/0b37279d-1674-42b4-b285-29683747ad9a.json"
#發(fā)送get請(qǐng)求
a?=?requests.get(url)
#獲取返回的json數(shù)據(jù),并賦值給data
data?=?a.json()
scatter.set_options(
{
????'appendPadding':?30,
????'data':?data,
????'xField':?'change?in?female?rate',
????'yField':?'change?in?male?rate',
????'sizeField':?'pop',
????'colorField':?'continent',
????'color':?['#ffd500',?'#82cab2',?'#193442',?'#d18768','#7e827a'],
????'size':?[4,?30],
????'shape':?'circle',
????'pointStyle':{'fillOpacity':?0.8,'stroke':?'#bbb'},
????'xAxis':{'line':{'style':{'stroke':?'#aaa'}},},
????'yAxis':{'line':{'style':{'stroke':?'#aaa'}},},
????'quadrant':{
????????'xBaseline':?0,
????????'yBaseline':?0,
????????'labels':?[
????????{'content':?'Male?decrease,\nfemale?increase'},
????????{'content':?'Female?decrease,\nmale?increase'},
????????{'content':?'Female?&?male?decrease'},
????????{'content':?'Female?&\n?male?increase'},?],},
})scatter.render_notebook()scatter.render("散點(diǎn)圖.html")
參數(shù)解釋 一
'appendPadding':?30,?#①
'data':?data,?#②
'xField':?'change?in?female?rate',?#③
'yField':?'change?in?male?rate',?
參數(shù)解釋 二
'sizeField':?'pop',?#④
'colorField':?'continent',?#⑤
'color':?['#ffd500',?'#82cab2',?'#193442',?'#d18768','#7e827a'],?#⑥
'size':?[4,?30],?#⑦
'shape':?'circle',?#⑧
參數(shù)解釋 三
'pointStyle':{'fillOpacity':?0.8,'stroke':?'#bbb'},?#⑨
'xAxis':{'line':{'style':{'stroke':?'#aaa'}},},?#⑩
'yAxis':{'line':{'style':{'stroke':?'#aaa'}},},
參數(shù)解釋 四
'quadrant':{
????'xBaseline':?0,
????'yBaseline':?0,
????'labels':?[
????{'content':?'Male?decrease,\nfemale?increase'},
????{'content':?'Female?decrease,\nmale?increase'},
????{'content':?'Female?&?male?decrease'},
????{'content':?'Female?&\n?male?increase'},?],},


評(píng)論
圖片
表情
