近期,又有接触到pyecharts这个包的使用,后面发现这个曾经好用的包发生了一些变化,为了方便大家的使用,这里整理如下:
绘图风格theme:默认WHITE
LIGHT, DARK, WHITE, CHALK, ESSOS, INFOGRAPHIC, MACARONS, PURPLE_PASSION, ROMA, ROMANTIC, SHINE, VINTAGE, WALDEN, WESTEROS, WONDERLAND
1.柱状图绘制
1.1 最基础的柱状图
from pyecharts.charts import Bar,Grid from pyecharts import options as opts from pyecharts.globals import ThemeType import random import numpy as np # 准备数据 name=["A","B","C","D"] salery=[random.randint(3000,5000) for i in range(4)] #绘图 bar=Bar(init_opts = opts.InitOpts(width='600px',height='400px')) bar.add_xaxis(name) bar.add_yaxis("salery",salery) bar.set_global_opts(title_opts=opts.TitleOpts(title="收入情况")) #仅在notebook中显示 bar.render_notebook() #在HTML中显示 bar.render("收入情况")
效果图:
1.2 稍微复杂的柱状图
为了减少代码量,此处不再导入包。绘制收入和消费情况,并使用新风格,并添加副标题,使用新版本的链式写法。
#准备数据 name=["A","B","C","D"] salery=[random.randint(3000,5000) for i in range(4)] cost=[random.randint(1000,2000) for i in range(4)] #绘图 bar=( Bar(init_opts = opts.InitOpts(width='600px',height='400px',theme=ThemeType.LIGHT)) .add_xaxis(name) .add_yaxis("salery",salery) .add_yaxis("cost",cost) .set_global_opts(title_opts=opts.TitleOpts(title="收入及消费情况",subtitle="随机样本")) ) bar.render_notebook()
#效果图:
1.3 堆叠式柱状图
使用堆叠式柱状图(部分堆叠),并自定义颜色,修改图例的显示位置,不显示数字,改变背景颜色
#准备数据 name=["A","B","C","D"] salery=[random.randint(3000,5000) for i in range(4)] cost=[random.randint(1000,2000) for i in range(4)] #所在城市平均薪水 salery_ave=[random.randint(3000,4000) for i in range(4)] colors=["#007892","#ff427f","#fc8210","#ffd8a6"] #进行绘图 bar=( Bar(init_opts = opts.InitOpts(width='600px',height='400px',bg_color=colors[-1])) .add_xaxis(name) .add_yaxis("salery",salery,stack="stack_one") .add_yaxis("cost",cost,stack="stack_one") .add_yaxis("salery_ave",salery_ave) .set_colors(colors) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="收入、消费及其城市平均收入情况"), legend_opts=opts.LegendOpts(type_="scroll", pos_right="right", orient="vertical") ) ) bar.render_notebook()
效果展示:
1.3.1 调整标题与图的位置
grid=Grid() # 分别调整上下左右的位置,参数为像素值或百分比 grid.add(bar,grid_opts=opts.GridOpts(pos_top="30%",pos_bottom="10%",pos_left="10%",pos_right="10%")) grid.render_notebook()
效果演示
1.4 绘制簇状图
#准备数据 name=["A","B","C","D"] salery=[random.randint(3000,5000) for i in range(4)] cost=[random.randint(1000,2000) for i in range(4)] #所在城市平均薪水 salery_ave=[random.randint(3000,4000) for i in range(4)] colors=["#007892","#ff427f","#fc8210","#ffd8a6"] #进行绘图 bar=( Bar(init_opts = opts.InitOpts(width='600px',height='400px',bg_color=colors[-1])) .add_xaxis(name) .add_yaxis("salery",salery) .add_yaxis("salery_ave",salery_ave) .reversal_axis() .set_colors(colors) .set_series_opts(label_opts=opts.LabelOpts(position="right")) .set_global_opts(title_opts=opts.TitleOpts(title="收入、消费及其城市平均收入情况"), legend_opts=opts.LegendOpts(type_="scroll", pos_right="right", orient="vertical") ) ) bar.render_notebook()
效果图演示
1.5 数据量大时的显示方法
#准备数据 name=[chr(i) for i in range(65,85,1)] salery=[random.randint(3000,5000) for i in range(20)] #所在城市平均薪水 salery_ave=[random.randint(3000,4000) for i in range(20)] colors=["#007892","#ff427f","#fc8210","#ffd8a6"] #绘图 修改 orient为vertical,可将滑动按钮移动垂直方向 bar=( Bar(init_opts = opts.InitOpts(width='600px',height='400px',bg_color=colors[-1])) .add_xaxis(name) .add_yaxis("salery",salery) .add_yaxis("salery_ave",salery_ave) .set_colors(colors) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="收入、消费及其城市平均收入情况"), legend_opts=opts.LegendOpts(type_="scroll", pos_right="right", orient="vertical"), datazoom_opts=[opts.DataZoomOpts(type_="slider")] ) ) bar.render_notebook()
演示效果:
2.绘制散点图
2.1 普通散点图
import random from pyecharts import options as opts from pyecharts.charts import Scatter from pyecharts.globals import ThemeType #准备数据 name=["A","B","C","D"] salery=[random.randint(3000,5000) for i in range(4)] cost=[random.randint(1000,2000) for i in range(4)] #所在城市平均薪水 salery_ave=[random.randint(3000,4000) for i in range(4)] colors=["#007892","#ff427f","#fc8210","#ffd8a6"] #进行绘图 scatter=(Scatter(init_opts = opts.InitOpts(width='600px',height='400px',theme=ThemeType.DARK)) .add_xaxis(name) .add_yaxis("salery",salery) .add_yaxis("cost",cost) .set_global_opts(title_opts=opts.TitleOpts(title="收入与消费情况"))) scatter.render_notebook()
查看效果:
2.2 3D散点图绘制
import random from pyecharts import options as opts from pyecharts.charts import Scatter3D from pyecharts.faker import Faker #准备数据 data = [(random.randint(0,100),random.randint(0,100),random.randint(0,100)) for i in range(50)] name=["长","宽","高"] #绘图 scatter3D=Scatter3D(init_opts = opts.InitOpts(width='600px',height='400px')) #初始化 scatter3D.add(name,data, grid3d_opts=opts.Grid3DOpts( width=100, depth=100 )) scatter3D.set_global_opts(title_opts=opts.TitleOpts(title="散点图"), visualmap_opts=opts.VisualMapOpts( range_color=Faker.visual_color #颜色映射 )) scatter3D.render_notebook()
效果图:
2.3 带涟漪的散点图
symbol的类型:
“pin”,“rect”,“roundRect”,“diamond”,“arrow”,“triangle”
import random from pyecharts import options as opts from pyecharts.charts import EffectScatter from pyecharts.globals import ThemeType #准备数据 name=["A","B","C","D"] salery=[random.randint(3000,5000) for i in range(4)] cost=[random.randint(1000,2000) for i in range(4)] #所在城市平均薪水 salery_ave=[random.randint(3000,4000) for i in range(4)] colors=["#007892","#ff427f","#fc8210","#ffd8a6"] #进行绘图 scatter=(EffectScatter(init_opts = opts.InitOpts(width='600px',height='400px',theme=ThemeType.DARK)) .add_xaxis(name) .add_yaxis("salery",salery,symbol="pin",symbol_size=20,symbol_rotate=180) .add_yaxis("cost",cost,symbol="rect",symbol_size=20) .set_global_opts(title_opts=opts.TitleOpts(title="收入与消费情况"), xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)), #添加网格 yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)) ) .set_series_opts(effect_opts=opts.EffectOpts(scale=3,period=2)) #调整涟漪的范围和周期 ) scatter.render_notebook()
效果图如下:
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]