We start by extracting the data from a previous project. The country column is converted to a categorical type, which simplifies handling in plotnine. To enable alternating row colors in the final visualization, we also create a new column called color_mod.
geom_segment(): Since I couldn’t find a way to apply border radius, I used geom_segment() with lineend="round" as the best available workaround. Thick lines serve as cell backgrounds.
Each line is added with a separate ax_text() call, which gives me more flexibility during alignment and styling. That said, I suspect there’s a cleaner way to do this.
Final Rendering
Now, let’s tie it all together:
p = plot_g()fig = themify(p)ax = fig.axes[0]ax = add_ax_text(ax)fig
Closing Thoughts
This post showcases how plotnine can be used to create table-like visualizations. I’m genuinely impressed by its capabilities — it’s surprisingly fun to approach a table as a figure.
That said, fine-tuning the layout and text positioning still feels a bit clunky at this stage. I hope to find a more structured and reliable way to handle that moving forward.
It would be exciting to explore how plotnine and Great Tables might work together to enable even richer visual storytelling — I’m looking forward to diving into that next.
Disclaimer
This table is intended as a self-practice project, and the data in the table may not be 100% accurate. Please refer to the original source if you require verified data.
This post was drafted by me, with AI assistance to refine the content.