如何使用Python和Plotly创建多行图?

发布于 2025-01-22 23:28:34 字数 413 浏览 3 评论 0 原文

使用Python和Plotly,我需要创建一个带有2行的图(对于 a ,对于 a ):

import plotly.express as px

a = [1, 2, 3, 4, 5]
b = [5, 4, 3, 2, 1]
fig = px.line([a, b])
fig.show()

但是我得到以下内容:

”

这?

With Python and Plotly I need to create one plot with 2 lines (for a and for a):

import plotly.express as px

a = [1, 2, 3, 4, 5]
b = [5, 4, 3, 2, 1]
fig = px.line([a, b])
fig.show()

However I am getting the following:

Plot

How to solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↘紸啶 2025-01-29 23:28:34

数据需要标题或标签。我的示例使用 pandas dataframe

import plotly.express as px
import pandas as pd

a = [1, 2, 3, 4, 5]
b = [5, 4, 3, 2, 1]

fig = px.line(pd.DataFrame({'line1':a, 'line2':b}))
# just dictionary will also work
# fig = px.line({'line1':a, 'line2':b})

fig.show()

The data need a title or label. My example uses a pandas dataframe:

import plotly.express as px
import pandas as pd

a = [1, 2, 3, 4, 5]
b = [5, 4, 3, 2, 1]

fig = px.line(pd.DataFrame({'line1':a, 'line2':b}))
# just dictionary will also work
# fig = px.line({'line1':a, 'line2':b})

fig.show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文