Daily Dose of Data Science

Daily Dose of Data Science

Share this post

Daily Dose of Data Science
Daily Dose of Data Science
Create a Moving Bubbles Chart in Python
Copy link
Facebook
Email
Notes
More

Create a Moving Bubbles Chart in Python

...in just three lines of code.

Avi Chawla's avatar
Avi Chawla
Apr 27, 2024
37

Share this post

Daily Dose of Data Science
Daily Dose of Data Science
Create a Moving Bubbles Chart in Python
Copy link
Facebook
Email
Notes
More
4
2
Share

Advertise | Deep Dives

I often come across the moving bubbles chart on LinkedIn.

I am sure you would have seen them too.

It is an elegant animation that depicts the movements of entities across time. They are particularly useful for determining when clusters appear in the data and at what state(s).

I always wondered how one can create them in Python.

Turns out, there’s a pretty simple way to do it just three lines of Python using D3Blocks.

The library utilizes the graphics of the popular d3js Javascript library to create visually appealing charts with only a few lines of Python code.

To create a moving bubbles chart, you can use the d3.movingbubbles() method.

The input should be a Pandas DataFrame. Each row should represent the state of a sample at a particular timestamp, as depicted below:

DataFrame format for moving bubbles chart using D3Blocks

After aligning the DataFrame in the desired format, you can create the moving bubbles chart as follows:

This will create an HTML file. You can preview it in a browser or open it in Jupyter directly using the IPython library.

I prepared this Jupyter notebook for you to get started: Moving Bubbles notebook.


That said, the utility of D3Blocks is not just limited to the Moving Bubbles Chart. One can do so much with it, as depicted below, with interactivity:

Image taken from the D3Blocks documentation

Why D3blocks when we already have Matplotlib, Plotly, Seaborn, etc.?

The issue with traditional frameworks is that they lose interactivity outside Python. In other words, you always need a Python-backed engine to maintain that interactivity.

With D3blocks, one can create highly customizable plots, which can be integrated with the web.

As a result, with D3blocks, one can create the chart in Python first. Next, they only need a browser to plot the graphs (interactively).

Isn’t that cool?

This Medium article by the creator of D3blocks, Erdogan Taskesen, is fantastic if you want to learn more: D3Blocks: The Python Library to Create Interactive and Standalone D3js Charts.

👉 Over to you: What other charts do you love creating in Python?

Thanks for reading!

Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (550+ pages) with 320+ tips.


Are you preparing for ML/DS interviews or want to upskill at your current job?

Every week, I publish in-depth ML dives. The topics align with the practical skills that typical ML/DS roles demand.

Join below to unlock all full articles:

I want to read super-detailed articles

Here are some of the top articles:

  • [FREE] A Beginner-friendly and Comprehensive Deep Dive on Vector Databases.

  • 8 Fatal (Yet Non-obvious) Pitfalls and Cautionary Measures in Data Science.

  • 5 Must-Know Ways to Test ML Models in Production (Implementation Included).

  • A Beginner-Friendly Guide to Multi-GPU Model Training.

  • 11 Powerful Techniques To Supercharge Your ML Models.

  • A Detailed and Beginner-Friendly Introduction to PyTorch Lightning: The Supercharged PyTorch

  • Don’t Stop at Pandas and Sklearn! Get Started with Spark DataFrames and Big Data ML using PySpark.

  • Federated Learning: A Critical Step Towards Privacy-Preserving Machine Learning.

  • You Cannot Build Large Data Projects Until You Learn Data Version Control!

  • Sklearn Models are Not Deployment Friendly! Supercharge Them With Tensor Computations.

Join below to unlock all full articles:

I want to read super-detailed articles


👉 If you love reading this newsletter, share it with friends!

Share Daily Dose of Data Science

👉 Tell the world what makes this newsletter special for you by leaving a review here :)

Review Daily Dose of Data Science

37

Share this post

Daily Dose of Data Science
Daily Dose of Data Science
Create a Moving Bubbles Chart in Python
Copy link
Facebook
Email
Notes
More
4
2
Share

Discussion about this post

User's avatar
M Khan's avatar
M Khan
Nov 18

https://open.substack.com/pub/mkhanshahani/p/the-most-effective-method-to-be-more?r=4q2315&utm_campaign=post&utm_medium=web&showWelcomeOnShare=true

Expand full comment
Reply
Share
M Khan's avatar
M Khan
Nov 18

https://open.substack.com/pub/mkhanshahani/p/the-most-effective-method-to-be-more?r=4q2315&utm_campaign=post&utm_medium=web&showWelcomeOnShare=true

Expand full comment
Reply
Share
2 more comments...

No posts

Ready for more?

© 2025 Avi Chawla
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More