在python3.7下的pyecharts新版(v1)下水滴图(liquid)的实例,资料来源官网,并进行加工和分析,便于小白系列学习。
1.首先明白自己的pyecharts是哪个版本?
1.1老版本:pyecharts v0.5
1.2新版本:pyecharts v1.0
1.3代码编写很大不同,网上新版本的代码很少,我也是一天时间自己摸索才搞懂,走了很多弯路,所以才写这篇,对于无人指点的小白,有很大的帮助。对于水滴图的图标代码也很少,所以对于小白和学习pyecharts的朋友都有很大的帮助。
2.liquid-无边框
2.1代码:
#导出模块
from pyecharts import options as opts
from pyecharts.charts import Liquid
from pyecharts.globals import SymbolType
#定义函数
c = (
Liquid()
.add("lq", [0.6, 0.7, 0.8], is_outline_show=False)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-无边框"))
)
c.render('1')#定格,括号内为文件名,注意单引号说明文件名省html后缀,双引号文件名,生成后缀,也可以加入路径,默认为代码.py所在的路径或文件夹。
2.2效果图:
3.Liquid-Shape-diamond
3.1 代码
from pyecharts import options as opts
from pyecharts.charts import Liquid,
from pyecharts.globals import SymbolType
c = (
Liquid()
.add("lq", [0.4, 0.7], is_outline_show=False, shape=SymbolType.DIAMOND)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-Shape-diamond"))
)
c.render('2')
3.2效果图
4.Liquid-Shape-arrow
4.1代码
from pyecharts import options as opts
from pyecharts.charts import Liquid
from pyecharts.globals import SymbolType
c = (
Liquid()
.add("lq", [0.3, 0.7], is_outline_show=False, shape=SymbolType.ARROW)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-Shape-arrow"))
)
c.render('3')
4.2效果图
5.Liquid-Shape-rect
5.1代码
from pyecharts import options as opts
from pyecharts.charts import Liquid
from pyecharts.globals import SymbolType
c = (
Liquid()
.add("lq", [0.3, 0.7], is_outline_show=False, shape=SymbolType.RECT)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-Shape-rect"))
)
c.render('4')
5.2效果图
6.Liquid-有框
6.1代码
from pyecharts import options as opts
from pyecharts.charts import Liquid
from pyecharts.globals import SymbolType
c = (
Liquid()
.add("lq", [0.6, 0.7])
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-有框"))
)
c.render('5')
6.2效果图
7.Liquid-数据精度
7.1代码:
from pyecharts import options as opts
from pyecharts.charts import Liquid
from pyecharts.commons.utils import JsCode
from pyecharts.globals import SymbolType
c = (
Liquid()
.add(
"lq",
[0.3254],
label_opts=opts.LabelOpts(
font_size=50,
formatter=JsCode(
"""function (param) {
return (Math.floor(param.value * 10000) / 100) + '%';
}"""
),
position="inside",
),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Liquid-数据精度"))
)
c.render('6')
7.2效果图
8.经典,值得收藏,分享给大家,共同学习,进步。