Hacker News

tosh
Plotnine plotnine.org

has2k14 hours ago

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.

jjgreen2 hours ago

Minor nit, the "Installing" link on the linked page leads to the general documentation.

x31233 minutes ago

Love your work on this, thanks for bringing the ggplot syntax to Python!

kasperset11 minutes ago

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.

seanhunter2 hours ago

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.

williamcotton2 hours ago

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!

tmoertel17 minutes ago

Nifty! What motivated you to create these tools?

williamcotton15 minutes ago

I really like to build things that build other things!

[deleted]an hour agocollapsed

skimmed2 hours ago

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

pwillia72 hours ago

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/;

qrobit6 hours ago

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...

has2k14 hours ago

Sorry for the confusion. Though, it is a mango tree in a mango garden! The continued development and maintenance of plotnine is supported by Posit, PBC, the same company behind the Tidyverse.

Disclaimer: I am the author.

quincymac3 hours ago

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!

has2k13 hours ago

There is this new and very promising package that adds interactivity to plotnine graphs https://y-sunflower.github.io/ninejs/.

Disclaimer: I am the author of plotnine.

a_ba4 hours ago

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/

jdthedisciple31 minutes ago

finally a mature matplotlib alternative?

vlad-asis2 hours ago

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

domoritz6 hours ago

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.

jpcompartir5 hours ago

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

piqufoh6 hours ago

`from plotnine import *`

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

jeroenjanssens5 hours ago

While it’s generally considered to be bad practice to import everything into the global namespace, I think it’s fine to do this in an ad-hoc environment such as a notebook as it makes using the many functions plotnine provides more convenient. An additional advantage is that the resulting code more closely resembles the original ggplot2 code. Alternatively, it’s quite common to `import plotnine as p9` and prefix every function with `p9`.

Disclaimer: I made the plotnine homepage and cheatsheet.

setr25 minutes ago

The issue I find with this pattern in docs/tutorials is that the prefix makes it very obvious which functions are from this library.

It's particularly worthwhile when looking at the bigger examples that might involve another library, or stdlib functions/libs I haven't dealt with before

clickety_clackan hour ago

To each his own. Some drawbacks here are that it means that if you want to copy the code in, you have to add all the “p9”s. And, if you want to make a more complicated demo, with maybe a second import, you now have multiple conventions in your demo codebase.

jamessb6 hours ago

> a new python plotting library

Whilst it's still not yet at 1.0.0, it's not that new: the first (0.1.0) release was in 2017: https://pypi.org/project/plotnine/#history

LoganDark6 hours ago

matplotlib's first release was in 2003, making it more than twice as old.

teruakohatu6 hours ago

Because most of the time this will be used is not part of a software development project but rather producing publication plots in a script or plots in a notebook. Not what you would want to do when incorporating it into a web app.

lmc39 minutes ago

Even in a notebook it's a pain... import plotnine as p9 would be nicer.

globular-toast6 hours ago

Because it's aimed at data scientists who would rather be using R...

jstanley6 hours ago

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

bittumenEntity3 hours ago

It is! And that's kinda the point.

Like others mention, this is inspired by ggplot2, a Grammar of Graphics library. The whole idea is graphics are composed by adding "layers", not like layers on a canvas, but like pouring paint into a pot, then the library understands the content and paints it to the canvas.

Layers might be pure data, geometry (lines, points, ...), annotations, styles, axis, etc.

When you get familiar with it, it's much more natural way of describing plots, better composition and easier exploration

bittumenEntity3 hours ago

And a side note, R actually includes a pipe operator (as in Unix `|`), and said if they'd know about it at the time, they would have never used the `+` operator

bbminneran hour ago

How `plot(.. + ggsize(700, 300) + ..)` is superior to a keyword parameter `plot(.. , size = (700, 300), ..)`?

1411333 minutes ago

Because, in the latter case, you have to declare a function argument for /every possible option/ that you want your graphics API to expose, and you need to do this every time you add a new option.

On the other hand, declaring the options through composition means that the API for "plot" remains static, and adding/removing options can be done trivially without an API change.

Composition (rather than parameters) is also more flexible. Let's say you want to divide your plot into three sub-plots, two of which are 200x200, and another which is 200x400. How do you express this as a keyword parameter? In composition, you could do something like:

plot( ggsubplot(ggvsplit(ggsize(200,400), gghsplit(ggsize(200,200), ggsize(200,200)))) )

jstanley20 minutes ago

And how do you express that as arithmetic?

I can get as far as `plot() / 3` but then no idea how to proceed. I don't think overloading arithmetic is a very good way to express this.

sdenton416 minutes ago

kwargs exists, and is rather more pythonic. Just pass the kwargs dict to a standard formatting function, et voila.

jamessb6 hours ago

Plotnine is heavily inspired by the ggplot2 library, which uses the + operator in the same way: https://ggplot2.tidyverse.org/#usage

wygzyan hour ago

Wonderful!!!

globular-toast6 hours ago

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.

vshulcz3 hours ago

[flagged]

hn-front (c) 2024 voximity
source