如何将 plotly 线图传输到 pandas 数据框?
How to pipe plotly line plot to pandas dataframe?
我们如何使用.pipe()
得到plotly express线图?
代码
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px
df = pd.DataFrame(data={'count':np.random.randint(1,20,10)},
index=pd.date_range('2020-01-01','2020-01-10')
)
线图(有效)
df1 = df.resample('2D').sum()
px.line(df1,x=df1.index,y='count')
使用管道
这里不需要创建df1。我们如何使用管道?
我的尝试
df.resample('2D').sum().pipe(px.line,x=lambda x: x.index,y='count')
# this does not work, gives empty plot
如何得到正确的图像?
你很接近:
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px
df = pd.DataFrame(data={'count':np.random.randint(1,20,10)},
index=pd.date_range('2020-01-01','2020-01-10')
)
# line plot with pipe
df.resample('2D').sum().pipe(lambda ts:
px.line(ts, x=ts.index,y='count'))
输出:
我们如何使用.pipe()
得到plotly express线图?
代码
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px
df = pd.DataFrame(data={'count':np.random.randint(1,20,10)},
index=pd.date_range('2020-01-01','2020-01-10')
)
线图(有效)
df1 = df.resample('2D').sum()
px.line(df1,x=df1.index,y='count')
使用管道
这里不需要创建df1。我们如何使用管道?
我的尝试
df.resample('2D').sum().pipe(px.line,x=lambda x: x.index,y='count')
# this does not work, gives empty plot
如何得到正确的图像?
你很接近:
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px
df = pd.DataFrame(data={'count':np.random.randint(1,20,10)},
index=pd.date_range('2020-01-01','2020-01-10')
)
# line plot with pipe
df.resample('2D').sum().pipe(lambda ts:
px.line(ts, x=ts.index,y='count'))
输出: