简体   繁体   English

如何在plotly中的同一canvas中添加两条线?

[英]How to add two line in the same canvas in plotly?

Hi I have a data frame with 3 columns嗨,我有一个包含 3 列的数据框

    number_of_episodes  mean_reward gamma
69995   69995   -19370.442404   0.100064
69996   69996   -19370.442404   0.100051
69997   69997   -19370.442404   0.100039
69998   69998   -19370.442404   0.100026
69999   69999   -19370.442404   0.100013

I use Plotly to plot the relationship between the number_of_episodes for each of the other two variables I can use the px.line to plot each one separately like this我使用 Plotly 到 plot 其他两个变量的number_of_episodes之间的关系 我可以使用px.line到 Z32FA6E1B78A9D4028953E60564A2AA4ZC 中的每一个

fig = px.line(df, x="number_of_episodes", y='mean_reward')
fig.show()

fig = px.line(df, x="number_of_episodes", y='gamma')
fig.show()

is there a way to plot both graphs in the same canvas?有没有办法将 plot 两个图放在同一个 canvas 中?

Since version 4.8 of Plotly you can simply call:由于 Plotly 的 4.8 版,您可以简单地调用:

fig = px.line(df, x="number_of_episodes", y=['mean_reward','gamma'])
fig.show()

https://community.plotly.com/t/announcing-plotly-py-4-8-plotly-express-support-for-wide-and-mixed-form-data-plus-a-pandas-backend/40048 https://community.plotly.com/t/announcing-plotly-py-4-8-plotly-express-support-for-wide-and-mixed-form-data-plus-a-pandas-backend/40048

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM