通過Python pyecharts輸出保存圖片代碼實例
安裝pyecharts:pip install pyecharts
安裝snapshot-selenium:pip install snapshot-selenium
安裝ChromeDriver:下載地址
注意:下載和電腦上的谷歌瀏覽器版本相同或者相近的版本,將ChromeDriver.exe放到項目文件所在文件夾即可。
代碼示例
from pyecharts.charts import Barfrom pyecharts import options as opts# 導(dǎo)入輸出圖片工具from pyecharts.render import make_snapshot# 使用snapshot-selenium 渲染圖片from snapshot_selenium import snapshot# 創(chuàng)建一個柱狀圖Bar實例bar = ( Bar() # 添加X軸數(shù)據(jù) .add_xaxis(['襯衫', '羊毛衫', '雪紡衫', '褲子', '高跟鞋', '襪子']) # 添加Y軸數(shù)據(jù),系列的名稱 .add_yaxis('商家A', [5, 20, 36, 10, 75, 90]) .add_yaxis('商家B', [8, 15, 60, 20, 25, 30]) # 添加標(biāo)題 .set_global_opts(title_opts=opts.TitleOpts(title='主標(biāo)題: 雙十一銷量', subtitle='副標(biāo)題:服飾類')))# 輸出保存為圖片make_snapshot(snapshot, bar.render(), 'Options配置項_自定義樣式_保存圖片.png')
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
