๐ The new, best lib for interactive Python charts?
Published 1 day agoย โขย 3 min read
๐ Hi!
This week I shared a new Python library called nineJs.
And to say the least... it got some echo:
โ
So today, let me explain what this is all about, and why so many people are excited about it! โ
By the way, before we dig in: my Python Dataviz Course is 50% off this week! It only happens once or twice a year, so if it's been on your radar, now's the moment!
To understand nineJs, you first need to understand plotnine.
plotnine is a very popular Python package that lets you use the R ggplot2 syntax... in Python!
As you might know, ggplot2 is quite famous for its awesome syntax. It's based on the grammar of graphics, which means a very natural, human friendly way to think and write about building charts.
plotnine lets you use exactly the same syntax... but with Python. Very handy and it gives you the same sensible default too.
Code to get a basic scatterplot with plotnine.
It's a common problem to have to switch from R to Python at work. Plotnine can make this transition seemless, at least for the dataviz side.
But that's just the beginning of the story.
Introducing nineJs
nineJs pushes it one step further. It lets you add a few lines of code to make the graph interactive.
The idea is simple: you take a chart you already built with plotnine, and you bring it to life. You can attach tooltips, hover effects that highlight groups of points, and click events.
And you declare all of it right inside aes(), exactly where you're already used to mapping your data.
โ
Two or three extra lines, and nineJs exports your chart as a standalone HTML file. No server, no heavy setup. It works out of the box with Jupyter, Quarto, Marimo and Shiny.
Why I love it
I love this approach compared to other libraries that make interactive charts with Python, for 3 reasons.
1๏ธโฃ โ No new syntax to learn. If you're familiar with ggplot2, it's very straightforward. You don't have a whole new grammar to discover. Just a bit of new code for the interactivity itself.
2๏ธโฃ โ Consistent. If you already have a chart designed, you truly start from it and make it interactive. Switching to another lib would mean rebuilding everything from scratch. Here, it's just about adding the interactivity on top.
3๏ธโฃ โ Flexible. It's based on the ggplot2 syntax, so you keep control over every possible customization. You won't get stuck fighting an inflexible API that blocks you from doing something.
โ Demo!
Take a look at the lib's demo page, it looks stunning! Here's a little gif that gives you an overview.
โ
โ Bottom line
This lib was created by Joseph Barbier. It's his 7th Python lib, and every day I'm more impressed by the quality of his work.
Joseph used to be my intern 2 years ago. Since then he hasn't stopped shipping awesome open source tools for the community.
We also built an in-depth course about dataviz with Python together. The best way to benefit from his tech knowledge about Python, and my knowledge about dataviz!
The course is 50% off exceptionally for 8 more days. If you want to build better graphs at work, you should join us! (your employer can pay for this ๐)
โ Yan โ PS: check a little selection of what previous students did! โ PPS: if you have any questions or doubts about this course, please hit reply! โ