yongrenjie / penguins

A Python 3 package for analysing and plotting NMR spectra.
https://yongrenjie.github.io/penguins
MIT License
5 stars 2 forks source link

Subclass Axes and add methods #7

Closed yongrenjie closed 4 years ago

yongrenjie commented 4 years ago

We’d need to override the return type of subplots as well.

yongrenjie commented 4 years ago

That would actually enable us to change the core plotting API, essentially combining stage() and mkplot() into one ax method. But that would mean we lose certain useful things like voffset, stacked, etc. I think it is more logical to retain the API

yongrenjie commented 4 years ago

https://stackoverflow.com/questions/44090563/in-python-how-can-i-inherit-and-override-a-method-on-a-class-instance-assignin

Benefit

Object-oriented code: ax.method(*args, **kwargs) instead of pg.func(ax=ax, *args, **kwargs)

Drawback

Forcing user into one single ecosystem (e.g. use pg.subplots() only, plt.subplots() not allowed) and extra confusion over which is appropriate

On balance, I think it's better to not do so. One thing I like very much about penguins is how it works seamlessly with matplotlib (because everything is done using "native" matplotlib classes / functions). We can stick with functions instead of methods.

yongrenjie commented 3 years ago

FWIW, seaborn made the same design choice as I did, so I feel a bit more confident that I'm right.