Creating Liquid (Waterball) Charts with PyEcharts in Python
This guide demonstrates how to install PyEcharts, import necessary modules, and use the Liquid chart class to create customizable waterball charts in Python, including setting colors, shapes such as rectangle, diamond, round‑rect, triangle, and arrow, and rendering them to HTML files.
The tutorial shows how to create liquid (waterball) charts using the PyEcharts library in Python.
First, install PyEcharts:
# Install the latest version of pyecharts
pip install pyechartsThen import the required modules:
from pyecharts import options as opts
from pyecharts.charts import LiquidThe basic chart displays a completion rate of 50%:
c = (
Liquid()
.add("Completion Rate", [0.5], is_outline_show=False)
.set_global_opts(title_opts=opts.TitleOpts(title="Business Completion", pos_left="center"))
.render("liquid_chart.html")
)To customize the color, add the color parameter:
c = (
Liquid()
.add("Completion Rate", [0.5], is_outline_show=False, color=['#DC143C'])
.set_global_opts(title_opts=opts.TitleOpts(title="Business Completion", pos_left="center"))
.render("liquid_chart.html")
)Different shapes can be set by importing SymbolType and using the shape argument:
from pyecharts.globals import SymbolType
c = (
Liquid()
.add("Completion Rate", [0.5], is_outline_show=False, shape=SymbolType.RECT)
.set_global_opts(title_opts=opts.TitleOpts(title="Business Completion", pos_left="center"))
.render("rect_liquid_chart.html")
)Replace SymbolType.RECT with SymbolType.DIAMOND , SymbolType.ROUND_RECT , SymbolType.TRIANGLE , or SymbolType.ARROW to obtain diamond, rounded‑rectangle, triangle, or arrow waterball charts respectively. Each variant can be rendered to its own HTML file.
All generated charts are saved as HTML files and can be viewed in a browser.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.