当前位置:   article > 正文

python钻石图_Python笔记:制作各种水球图

pyecharts 水球图 改颜色

前言:用pyecharts v1.x版本来绘制水球图。

注:Ppyecharts分为 v0.5.x 和 v1.x 两个大版本,v0.5.x 和 v1.x 间不兼容,v0.5.x是基于Python2.7+、3.4+版本开发的,而v1.x是一个全新的版本,它是基于Python3.6+版本开发的,另外经PyEcharts开发团队决定,0.5.x 版本将不再进行维护。

前提:

# 安装pyecharts模块,直接安装就是最新的版本

pip install pyecharts

#导包

from pyecharts import options as opts

from pyecharts.charts import Liquid

水球图数据很简单,就是一个完成率数字,所以不用定义或导入,也无需做转换。

接下来就可以绘制水球图了:

from pyecharts import options as opts

from pyecharts.charts import Liquid

c = (

#创建水球图对象

Liquid()

#设置数据系列名称及数据,is_outline_show是设置边框线,根据自身喜欢选择

.add("达成率", [0.66], is_outline_show = False)

# 设置图表标题及位置

.set_global_opts(title_opts = opts.TitleOpts(title = "蔬菜部门销售达成率",pos_left = "center"))

#通过render()方法将水球图渲染为html

# .render("圆形水球图.html")

)

c.render_notebook()

94bf29dd52809ee3942504b961977678.png

水球图的颜色可以设置,只需要add()中添加color参数,代码如下:

from pyecharts import options as opts

from pyecharts.charts import Liquid

c = (

Liquid()

.add("达成率", [0.88], is_outline_show = False, color = ['#DC143C'])

.set_global_opts(title_opts = opts.TitleOpts(title = "水果部门销售达成率",pos_left = "center"))

# .render("圆形水球图.html")

)

c.render_notebook()

红色的水球:

ea35b616d494e8a1140cfaf57bc03ef9.png

水球的形状也可以自定义:

from pyecharts import options as opts

from pyecharts.charts import Liquid

from pyecharts.globals import SymbolType

c = (

Liquid()

.add("达成率", [0.777], is_outline_show = False, shape = SymbolType.RECT)

.set_global_opts(title_opts = opts.TitleOpts(title = "水产销售达成率",pos_left = "center"))

# .render("矩形水球图.html")

)

c.render_notebook()

矩形水球:

60b259aaa7d1ee2f87ef34ed8547841d.png

from pyecharts import options as opts

from pyecharts.charts import Liquid

from pyecharts.globals import SymbolType

c = (

Liquid()

.add("达成率", [0.90], is_outline_show = False, shape = SymbolType.DIAMOND)

.set_global_opts(title_opts = opts.TitleOpts(title = "综合部门销售达成率",pos_left = "center"))

# .render("矩形水球图.html")

)

c.render_notebook()

看出区别了吗?只要在add()中添加shape=SymbolType.RECT的设置,同时需要导入对应的模块:from pyecharts.globals import SymbolType

另外shape=SymbolType.DIAMOND就是钻石水球图

9165f7044b34ad03471b8b68699cff3f.png

from pyecharts import options as opts

from pyecharts.charts import Liquid

from pyecharts.globals import SymbolType

c = (

Liquid()

.add("达成率", [0.60], is_outline_show = False, shape = SymbolType.ROUND_RECT)

.set_global_opts(title_opts = opts.TitleOpts(title = "电商部门销售达成率",pos_left = "center"))

# .render("矩形水球图.html")

)

c.render_notebook()

shape=SymbolType.ROUND_RECT就是圆角矩形水球图

1eba2f3db88a4e23d73e674c9661d763.png

from pyecharts import options as opts

from pyecharts.charts import Liquid

from pyecharts.globals import SymbolType

c = (

Liquid()

.add("达成率", [0.67], is_outline_show = False, shape = SymbolType.TRIANGLE)

.set_global_opts(title_opts = opts.TitleOpts(title = "猪肉部门销售达成率",pos_left = "center"))

# .render("矩形水球图.html")

)

c.render_notebook()

shape=SymbolType.TRIANGLE就是三角形水球图

a806883cd90ef2ab3a1c87838e22b376.png

from pyecharts import options as opts

from pyecharts.charts import Liquid

from pyecharts.globals import SymbolType

c = (

Liquid()

.add("达成率", [0.56], is_outline_show = False, shape = SymbolType.ARROW)

.set_global_opts(title_opts = opts.TitleOpts(title = "物料部门销售达成率",pos_left = "center"))

# .render("矩形水球图.html")

)

c.render_notebook()

shape=SymbolType.ARROW就是箭头水球图

7812ea0e7084547d8b0c9cac1d1cb31e.png

制作水球图不是很简单的吗(?_?)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/196652
推荐阅读
相关标签
  

闽ICP备14008679号