feat: exploring bumplot as plotnine geoms - #15
Conversation
|
Hi @machow That's a great idea! I hadn't thought of that. In my opinion, it makes sense for In ggbump, they included a I don't have much time to think about it right now, but it seems like you already have a pretty good idea on how this could/should be implemented, so if you're willing to work on a more "complete" PR (with @has2k1 ?), I'd be happy to review it, as this would be a very cool addition to |
|
Thanks for getting back on this! The TLDR is I'll work on getting this PR ready (and check it with Hassan)! It's been helpful to dig a bit more into matplotlib, and also see narwhals plugged into bumplot.
That seems great to me! A lot of my interest is in how it gets extended, so I'll largely just try to squirrel away notes on extensions to add to the plotnine user guide 😁.
|
|
(I see you're working on this, thanks! feel free to ping me whenever you need review/help/whatever) |
|
Alright -- after looking a bit more at ggbump, I've implemented a stat called
RE bezier vs sigmoid: I looked a bit and it seems bezier curves might not use a sigmoid function? I left it as bezier, in case this detail is important. But I didn't look into the bezier code, and am happy to change it if sigmoid seems like a better name! @has2k1 do you want to take a look at this, in case I messed up any plotnine bits? I added you as a collaborator on the fork, so feel free to push updates! |
|
@JosephBARBIERDARNAL thanks for approving the CI run! One piece I wanted to check -- do you have a sense for how you might want this tested? I'm happy to try reproducing any examples / creating plots that use any paths (e.g. setting the different aesthetics!) edit: here's the code I used to test the geom! # %%
import pandas as pd
from plotnine import (
ggplot,
aes,
geom_point,
theme_minimal,
scale_color_manual,
scale_fill_manual,
scale_y_reverse,
)
from bumplot.geoms import geom_bump, geom_bezier
data = pd.DataFrame(
{
"x": [2020, 2021, 2022, 2023],
"A": [10, 50, 20, 80],
"B": [40, 30, 60, 10],
"C": [90, 20, 70, 40],
}
)
data_long = data.melt(id_vars="x", value_vars=["A", "B", "C"])
(
ggplot(data_long, aes("x", "value"))
+ geom_bump(aes(color="variable"), size=1)
# note the rank stat used below
+ geom_point(aes(fill="variable"), size=3, color="black", stat="rank")
# match readme plot ----
+ theme_minimal()
+ scale_fill_manual(values=["#ffbe0b", "#ff006e", "#3a86ff"])
+ scale_color_manual(values=["#ffbe0b", "#ff006e", "#3a86ff"])
# TODO: scale y reverse showing negative numbers?
# + scale_y_reverse()
) |
|
|
||
| """ | ||
|
|
||
| # TODO: I get an error if I don't set geom here, |
There was a problem hiding this comment.
@has2k1 I got an error if I didn't have "geom" in the DEFAULT_PARAMS. Do you know if all stats are required to have a default geom, or is there a way to not have a default?
There was a problem hiding this comment.
Yes, all stats should have a default geom. The goal of every geom or stat is to create a layer, they simplify creating layers. A layer has both a geom and a stat. That is why geoms have default stats and stats have default geoms.
You're right about sigmoid, it does not make that much sense mathematically. It just sounds more intuitive for users (or not?), so |
I'm not entirely sure what is the best way to test a plotnine object, but you can take inspirations of what I did in Edit while I'm writing: I'll make a todo for this PR at the top of this page with everything I think make sense. |
With plotnine you can also get the Axes object and inspect it for the expected artists. p = ggplot(...) + geom_bump(...)
fig = p.draw()
ax = fig.get_axes()[0]
... |
(edit) TODO:
geom_bump()&geom_bezier()curve_force: float(nice feature IMO)docs/index.md) and readme (docs/REAME.qmd): maybe the same made with matplotlib?docs/examples.mdand (nice to have but takes a significant amount of time, feel free to skip this one, see add good/advanced examples in the doc #3) example indocs/advanced-usage.mdbumplot()(just make sure things are consistent)Hey @JosephBARBIERDARNAL! Don't hesitate to punt this PR, but I've been really interested in trying bumplot, while also working a bit on plotnine extensions. I decided to try out using bumplot from plotnine to see what kind of work is involved.
This is still a WIP, but I implemented a
geom_bezier()using the bumplotbezier_curve()function. I think if you're up for it @has2k1 is down to help withgeom_bezier()and a biggergeom_bumplot(). It could either live here or somewhere else. WDYT?!Here it is recreating the plot from the README.
It seems like this kind of bumplot stuff would be neat to show off in the 2025 Plotnine Plotting Contest 😁