`from plotnine import *` ... I love the idea of a new python plotting library, but why is this anti-pattern so common with plotting libs?
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 ever…
Plotnine
31–40 of 83 posts
Re: Plotnine
#32`from plotnine import *` ... I love the idea of a new python plotting library, but why is this anti-pattern so common with plotting libs?
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.
Re: Plotnine
#33Earlier quoted context omitted.
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 familia…
How `plot(.. + ggsize(700, 300) + ..)` is superior to a keyword parameter `plot(.. , size = (700, 300), ..)`?
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)))) )
Re: Plotnine
#34If 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.
Re: Plotnine
#35Re: Plotnine
#36`from plotnine import *` ... I love the idea of a new python plotting library, but why is this anti-pattern so common with plotting libs?
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 ever…
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
Re: Plotnine
#37Earlier quoted context omitted.
How `plot(.. + ggsize(700, 300) + ..)` is superior to a keyword parameter `plot(.. , size = (700, 300), ..)`?
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 als…
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.
Re: Plotnine
#38I'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.gi…
Re: Plotnine
#39Earlier quoted context omitted.
How `plot(.. + ggsize(700, 300) + ..)` is superior to a keyword parameter `plot(.. , size = (700, 300), ..)`?
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 als…
Re: Plotnine
#40I'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.gi…
Nifty! What motivated you to create these tools?