← Back to list

Data Visualization | Python Beautiful Animated Liquid Ball Chart

“Liquid Ball Chart” is a chart type that is very suitable for presenting percentage data. In our project, we often need to regularly report…

Gen. Devin DL. · 2023-11-12 07:39 · 15 claps · 2.5 min read
#pyecharts #python-pyecharts #liquid-ball-chart #data-visualization-python #python-animation
Open on Medium ↗
Wiki topics: VIS · Visual & Graphic Design 🎬 · Film & Television

Data Visualization | Python Beautiful Animated Liquid Ball Chart

“Liquid Ball Chart” is a chart type that is very suitable for presenting percentage data. In our project, we often need to regularly report work progress, such as completion rate 30%, performance achieved 90%, and so on. Using a liquid ball chart can achieve a very effective data presentation.

In this post below, we will introduce how to implement a liquid ball chart visualization in Python.

  1. pyecharts installation
pip install pyecharts
  1. importing modules
from pyecharts import options as opts
from pyecharts.charts import Grid, Liquid
from pyecharts.commons.utils import JsCode
  1. drawing liquid ball charts

Basic liquid ball chart:

c1 = (
    Liquid()
    .add('lq',
         [0.35],
         center=['30%', '50%'],
         is_outline_show=False,
         shape='circle'
         )
    .set_global_opts(title_opts=opts.TitleOpts(title='basic-waterball-1',pos_top='30',pos_left='10%'))
    .render('basic-waterball-1.html')
)

The result is as shown below:

The waterdrop shape can be one of the following options: “circle, rect, roundRect, triangle, diamond, pin, arrow.” You can choose the shape using the ‘shape’ parameter, with the default value being ‘circle.’

Add borders and change shapes:

c2 = (
    Liquid()
    .add('lq',
         [0.35],
         center=['30%', '50%'],
         is_outline_show=True,
         shape='roundRect'
         )
    .set_global_opts(title_opts=opts.TitleOpts(title='basic-waterball-2',pos_top='30',pos_left='10%'))
    .render('basic-waterball-2.html')
)

The result is as shown below:

The is_outline_show parameter can be set to determine whether to display the outline.

c3 = (
    Liquid()
    .add('lq',
         [0.75,0.5,0.2],
         center=['30%', '50%'],
         is_outline_show=True,
         shape='roundRect'
         )
    .set_global_opts(title_opts=opts.TitleOpts(title='basic-waterball-3',pos_top='30',pos_left='10%'))
    .render('basic-waterball-3.html')
)

The result is as shown below:

Adding Annotations

Change font size and fill color

c4 = (
    Liquid()
    .add('lq',
         [0.6],
         center=['30%', '50%'],
         is_outline_show=True,
         shape='diamond',
         color=['#008B8B'],
         label_opts = opts.LabelOpts(font_size=25, formatter=JsCode(
            """function (param) {
                    return ('Percentage:'+Math.floor(param.value * 10000) / 100) + '%';
                }"""
            ),position='inside'),
         )
    .set_global_opts(title_opts=opts.TitleOpts(title='basic-liquid-ball-4',pos_top='30',pos_left='10%'))
    .render('basic-liquid-ball-4.html')
)

The result is as shown below:

Displaying multiple charts side by side:

from pyecharts import options as opts
from pyecharts.charts import Grid, Liquid
from pyecharts.commons.utils import JsCode

l1 = (
    Liquid()
    .add('lq',
         [0.2],
         shape='circle',
         center=['20%', '50%'],
         label_opts=opts.LabelOpts(
             font_size=20,
             formatter=JsCode(
                """function (param) {
                        return ('Percentage:'+Math.floor(param.value * 10000) / 100) + '%';
                    }"""
            ),
            position='inside',
            ),
        )
)

l2 = (
    Liquid()
    .add('lq',
         [0.5,0.3],
         shape='diamond',
         center=['50%', '50%'],
         label_opts=opts.LabelOpts(
             font_size=20,
             formatter=JsCode(
                """function (param) {
                        return ('Percentage:'+Math.floor(param.value * 10000) / 100) + '%';
                    }"""
            ),
            position='inside',
            ),
        )
)

l3= Liquid().add(
    'lq',
    [0.85, 0.5, 0.2],
    shape='roundRect',
    center=['80%', '50%'],
    label_opts=opts.LabelOpts(
        font_size=20,
        formatter=JsCode(
            """function (param) {
                    return ('Percentage:'+Math.floor(param.value * 10000) / 100) + '%';
                }"""
        ),
        position='inside',
    ),
)

grid = Grid().add(l1, grid_opts=opts.GridOpts()).add(l2, grid_opts=opts.GridOpts()).add(l3, grid_opts=opts.GridOpts())
grid.render('basic-liquid-ball-5.html')

The result is as shown below:


메타데이터
post_id
efbe7b110dde
slug
data-visualization-python-beautiful-animated-liquid-ball-chart-efbe7b110dde
url
https://medium.com/@tubelwj/data-visualization-python-beautiful-animated-liquid-ball-chart-efbe7b110dde
canonical_url
https://medium.com/@tubelwj/data-visualization-python-beautiful-animated-liquid-ball-chart-efbe7b110dde
author_url
https://medium.com/@tubelwj
status
ok
fetched_at
2026-09-10 02:11:23