如何用 plotly 绘制一个 x 轴和两个 y 轴的直线曲线?
How to plot line curve with one x axis and two y axis with plotly?
我有一个包含两列日期和金额的数据框。我可以用 matplotlib 绘制那些,但无法用 plotly 绘制。下面是matplotlib例子
result.Amount[:362].plot(figsize=(15,8), title= 'Credit Amount by date', fontsize=14)
result.Amount[362:].plot(figsize=(15,8), title= 'Credit Amount by date', fontsize=14)
plt.show()
输出为:
但是当我尝试使用 plotly 进行相同操作时,它不起作用。我为 plotly 编写的代码是
fig = px.line(result, x='Date', y=[Amount[:362], Amount[362:]], template = 'plotly_dark')
fig.show()
它正在返回类似
的错误
NameError Traceback (most recent call last)
<ipython-input-61-449ab60f9636> in <module>
1 # line plot
2
----> 3 fig = px.line(result, x='Date', y=[Amount[:362], Amount[362:]], template = 'plotly_dark')
4
5 # add a vertical rectange for test-set separation
NameError: name 'Amount' is not defined
https://drive.google.com/file/d/10TN_FSs27r5agLUv4aoopfaRpGsnIG5m/view?usp=sharing
以上为link数据
谁能帮我解决这个问题?
使用plotly.graph_objects,您可以在一个图形中绘制多个图形。
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=df['Date'][:362], y=df['Amount'][:362], mode='lines', name='A'))
fig.add_trace(go.Scatter(x=df['Date'][362:], y=df['Amount'][362:], mode='lines', name='B'))
fig.show()
我有一个包含两列日期和金额的数据框。我可以用 matplotlib 绘制那些,但无法用 plotly 绘制。下面是matplotlib例子
result.Amount[:362].plot(figsize=(15,8), title= 'Credit Amount by date', fontsize=14)
result.Amount[362:].plot(figsize=(15,8), title= 'Credit Amount by date', fontsize=14)
plt.show()
输出为:
但是当我尝试使用 plotly 进行相同操作时,它不起作用。我为 plotly 编写的代码是
fig = px.line(result, x='Date', y=[Amount[:362], Amount[362:]], template = 'plotly_dark')
fig.show()
它正在返回类似
的错误NameError Traceback (most recent call last)
<ipython-input-61-449ab60f9636> in <module>
1 # line plot
2
----> 3 fig = px.line(result, x='Date', y=[Amount[:362], Amount[362:]], template = 'plotly_dark')
4
5 # add a vertical rectange for test-set separation
NameError: name 'Amount' is not defined
https://drive.google.com/file/d/10TN_FSs27r5agLUv4aoopfaRpGsnIG5m/view?usp=sharing
以上为link数据
谁能帮我解决这个问题?
使用plotly.graph_objects,您可以在一个图形中绘制多个图形。
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=df['Date'][:362], y=df['Amount'][:362], mode='lines', name='A'))
fig.add_trace(go.Scatter(x=df['Date'][362:], y=df['Amount'][362:], mode='lines', name='B'))
fig.show()