Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python class methods operator #912

Open
wangjiawen2013 opened this issue Jan 26, 2025 · 1 comment
Open

python class methods operator #912

wangjiawen2013 opened this issue Jan 26, 2025 · 1 comment
Labels

Comments

@wangjiawen2013
Copy link

wangjiawen2013 commented Jan 26, 2025

Hi,
Plotnine uses + operator to concatenate multiple graphical elements to keep the consistant API with R ggplot2, while python altair (https://altair-viz.github.io/user_guide/data.html#user-guide-data) uses . instead. It is known that the . operator is more natural for python Classes. Just curious and want to know how do you make + operator available for python Classes. Operator overloading or some other techniques ?

@TyberiusPrime
Copy link
Contributor

TyberiusPrime commented Jan 26, 2025

They simply implement __add__ or __radd__, see https://docs.python.org/3/reference/datamodel.html#object.__add__

There are wrappers around plotnine that convert it into a fluent API (i.e. methods that return self,so you can chain them like plot.add_point().scale_y_continous().render) such as dppd_plotnine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants