我正在尝试使用 plotly 绘制 1993 年至 2020 年收益率差的折线图。在名为“data”的数据框中,变量的名称是“yieldsp”。它是一个具有 DateTime 索引的时间序列数据,如下所示:
data['yieldsp'].head()
Date
1993-10-01 2.36
1993-10-04 2.32
1993-10-05 2.29
1993-10-06 2.31
1993-10-07 2.28
Name: yieldsp, dtype: float64
data.index
DatetimeIndex(['1993-10-01', '1993-10-04', '1993-10-05', '1993-10-06',
'1993-10-07', '1993-10-08', '1993-10-12', '1993-10-13',
'1993-10-14', '1993-10-15',
...
'2020-06-12', '2020-06-15', '2020-06-16', '2020-06-17',
'2020-06-18', '2020-06-19', '2020-06-22', '2020-06-23',
'2020-06-24', '2020-06-25'],
dtype='datetime64[ns]', name='Date', length=6688, freq=None)
我写了下面的代码来获取情节:
# Using plotly.express
import plotly.express as px
#data = px.data.iris()
fig = px.line(data['yieldsp'], x = data.index, y ='Yield Spread', line_shape="spline", render_mode="svg")
fig.show()
沧海一幻觉
相关分类