juba / pyobsplot

Observable Plot in Jupyter notebooks and Quarto documents
https://juba.github.io/pyobsplot/
MIT License
184 stars 8 forks source link

Make shorthand definition possible #18

Open harrylojames opened 1 year ago

harrylojames commented 1 year ago

Hi,

In line with having a syntax as close as possible to javascript it would nice to be able to use the shorthand syntax as seen here.

import pandas as pd
from pyobsplot import Plot

df = pd.DataFrame({'Date': {0: '1880-01-01', 1: '1880-02-01'}, 'Anomaly': {0: -0.3, 1: -0.21}})
Plot.lineY(df, {"x": "Date", "y": "Anomaly"}).plot()
AttributeError                            Traceback (most recent call last)
Cell In[15], line 5
      2 from pyobsplot import Plot
      4 df = pd.DataFrame({'Date': {0: '1880-01-01', 1: '1880-02-01'}, 'Anomaly': {0: -0.3, 1: -0.21}})
----> 5 Plot.lineY(df, {"x": "Date", "y": "Anomaly"}).plot()

AttributeError: 'dict' object has no attribute 'plot'

Not sure how feasible this is and not a dealbreaker for me but thought it was worth noting in case it wasn't on the radar.

Many thanks,

Harry

juba commented 1 year ago

I'm not sure I would be able to implement this given the way python Plot methods are automatically generated, but this is indeed a very valid suggestion.

I keep this open, thanks for the idea !