近期,又有接触到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()
效果图如下:
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 群星.2003-存为爱2CD【环球】【WAV+CUE】
- 韩磊《试音天碟》高清音频[WAV+CUE]
- 邓涛《寂寞蒲公英(黑胶CD)》[WAV]
- 江志丰.2011-爱你的理由【豪记】【WAV+CUE
- 群星《传承-太平洋影音45周年纪念版 (CD2)》[320K/MP3][140.01MB]
- 群星《传承-太平洋影音45周年纪念版 (CD2)》[FLAC/分轨][293.29MB]
- 首首经典《滚石红人堂I 一人一首成名曲 4CD》[WAV+CUE][2.5G]
- s14上单t0梯度怎么排名 s14世界赛上单t0梯度排行榜
- tes目前进了几次s赛 LPL队伍tes参加全球总决赛次数总览
- 英雄联盟巅峰礼赠什么时候开始 2024巅峰礼赠活动时间介绍
- 冯骥发文谈睡觉重要性 网友打趣:求求你先做DLC
- 博主惊叹《少女前线2》万圣节大雷皮肤:这真能过审吗?
- 《生化危机8》夫人比基尼Mod再引骂战:夸张身材有错吗?
- 江蕙.1994-悲情歌声【点将】【WAV+CUE】
- 戴娆.2006-绽放【易柏文化】【WAV+CUE】