logoalt Hacker News

Plotnine

190 pointsby toshlast Friday at 9:08 AM63 commentsview on HN

Comments

closedtoday at 3:35 PM

Hey! I worked on the plotnine guide (https://plotnine.org/guide/). Always interested to hear what people find hard to understand about plotnine, or what they wish there were more of (e.g. examples, guide pages, api reference docs).

(Both has2k1 and I work for Posit, which supports plotnine work, but authoring its guide was mostly an act of passion for me :)

fifiluratoday at 4:37 PM

It is great, but I have completely given up non-interactive plots since a while.

You get so much more information in plots using bokeh (or I assume plotly).

Tooltips, zooming, interaction.

And the LLM helps a lot when the plot is a bit more complex.

seanhuntertoday at 1:02 PM

Plotnine has been great in my usage, but I see violin plots on the front page. Just say no to violin plots.

In almost any situation you either want to talk about the actual distribution (in which case plotting the distribution on one side of the line arranged horizontally is significantly superior to plotting it vertically on both sides of the line for some reason as a violin plot does[1]) or you want to talk about the quartiles etc in which case a boxplot is better.

A violin plot tries to do both and as a result does them both badly.

Extended anti-violin plot rant here https://www.youtube.com/watch?v=_0QMKFzW9fw

[1] I remember in one meeting before I knew better, producing some violin plots and putting them on a slide and I knew I had gone wrong when that slide came up and everyone in the room had this confused expression on their faces and was leaning their head over to the side to try to see the distribution better. When your visualization produces obvious confusion like that, you can be completely certain it has failed.

show 3 replies
has2k1today at 10:29 AM

If you already use plotnine, or if this has piqued your interest, the next release (v0.16.0) will bring nice capabilities.

You can get a sneak peek by installing the pre-release:

pip install --pre plotnine

Details here: https://github.com/has2k1/plotnine/issues/1031

Disclaimer: I'm the author.

show 2 replies
williamcottontoday at 12:38 PM

I've always liked the ggplot2 and the Grammar of Graphics approach to plotting so much so that I wrote my own DSL based on it - it is standalone, written in Rust, has WASM bindings (as you can see on the website) and more:

https://williamcotton.github.io/algraf

It pairs well with a related data translation DSL:

https://williamcotton.github.io/pdl

And you can see the two working together here:

https://williamcotton.github.io/datafarm-studio

There's LSPs for both, LSP clients for VS Code, and even language diagnostics for standalone Monaco editors in the browser.

Of note is that the same language diagnostics are exposed via the WASM as via the LSP interface allowing for the same friendly red squiggles to look and work the same in both your browser with Monaco and your editor with the LSP!

show 3 replies
kaspersettoday at 2:29 PM

While it is good to have plotnine for python but ggplot2 in R has this whole ecosystem of packages/extensions that augment the ggplot2 such as ggalluvial, ggrepel. More at this link https://exts.ggplot2.tidyverse.org/gallery/ This would make it really compelling to tip my toes in the Python world. Regardless, I am liking this "ggplotification" of python. All we need is more "tidification" of Python data frame world.

icarusztoday at 2:50 PM

matplotlib is what most folks reach for by default, but I'd argue that's habit and popularity talking, not a real fit advantage. For a lot of plotting work, the grammar-of-graphics libraries — Altair, plotnine — may be the better tool for many people (and Agents); they just don't have the muscle memory behind them.

(Disclosure: I'm at Posit, which supports plotnine.)

show 2 replies
qrobittoday at 9:01 AM

And it comes with tidyverse-like cheatsheet[1] that I confused with ggplot2 when first discovered plotnine

[1]: https://github.com/rstudio/cheatsheets/blob/main/plotnine.pd...

CuriouslyCtoday at 3:58 PM

Is the selling point for this vs e.g. Plotly just the ggplot style semantics?

show 1 reply
skimmedtoday at 1:08 PM

Nice package! A side-by-side comparison with seaborn would be very nice to see.

persedestoday at 2:49 PM

Love plotnine when I switched over to python and great to see the project develop! But I have to admit I ended up switching to altair after all which has been my go to in python now.

a_batoday at 11:07 AM

I have used neither in quite a while now but there is an alternative from jetbrains that i started using because it shares the same ergonomics and had better (?) documentation.

https://lets-plot.org/python/

show 1 reply
pwillia7today at 12:56 PM

Very cool will have to check this out more.

Semi related -- I made a little d3.js AI wrapper that works pretty well for making quick charts -- https://prompt2chart.com/share/e998a3f6-9482-4c18-931f-a4513...; https://prompt2chart.com/;

vlad-asistoday at 12:51 PM

I always like to see Hadley Wickam’s masterpiece frameworks emerging around.

staredtoday at 3:15 PM

See also Gribouille: A Grammar of Graphics for Typst, discussed here a week ago https://news.ycombinator.com/item?id=48541062.

quincymactoday at 11:50 AM

Nice one. I'm aware of plotnine because ggplot is more intuitive IMHO than say matplotlib.

2 things that would be awesome are interactive plots (hover + text box) and chlorpleth (tiled map) plots.

On closer look you have already nailed the latter!

show 1 reply
domoritztoday at 8:32 AM

For another grammar-of-graphics-based visualization library (flexibly compose charts rather than simply pick a template), check out Altair https://altair-viz.github.io.

jpcompartirtoday at 9:57 AM

After plotnine, with a solid & performant (more than the R versions) Python version of Purrr and Dplyr I might never reach for R again!

insane_dreamertoday at 3:11 PM

How does it handle realtime plotting?

datadrivenangeltoday at 3:14 PM

Plotnine is my favorite python viz package, because ggplot2 is just so good.

Altair and Bokeh are also quite good for interactive graphs, but plotnine is so ergonomic.

piqufohtoday at 8:36 AM

`from plotnine import *`

... I love the idea of a new python plotting library, but why is this anti-pattern so common with plotting libs?

show 4 replies
jstanleytoday at 8:20 AM

Using operator overloading of "+" to configure the plot is... a choice.

show 1 reply
jdthediscipletoday at 2:10 PM

finally a mature matplotlib alternative?

show 1 reply
globular-toasttoday at 8:38 AM

Back when I did a lot of data stuff I used ggplot in R because it seemed to be popular, but I was just copy/pasting examples. Then one day I finally started to "get it" and actually read the manual. Learning the grammar of graphics was like a super power. I got to the point I could open pretty much anything people sent me and visualise it in a matter of seconds.

Although I've used Python professionally a lot more than R, I still felt like R was better at this. Somehow opening files in Python always feels a bit more "heavy". I don't really know why, though.

wygzytoday at 1:35 PM

Wonderful!!!