以下是示例数据:

Datetime   Price  Data1  Data2  ShiftedPrice
0 2017-11-05 09:20:01.134  2123.0  12.23  34.12         300.0
1 2017-11-05 09:20:01.789  2133.0  32.43  45.62         330.0
2 2017-11-05 09:20:02.238  2423.0  35.43  55.62           NaN
3 2017-11-05 09:20:02.567  3423.0  65.43  56.62           NaN
4 2017-11-05 09:20:02.948  2463.0  45.43  58.62           NaN

我试图在Datetime和Shiftedprice列之间绘制一个图,并在ShiftedPrice列的平均值,置信区间绘制水平线 . 看看下面的代码:

import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np

df1 = df.dropna(subset=['ShiftedPrice'])
df1
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(121)
ax = df1.plot(x='Datetime',y='ShiftedPrice')

# Plotting the mean
ax.axhline(y=df1['ShiftedPrice'].mean(), color='r', linestyle='--', lw=2)
plt.show()

# Plotting Confidence Intervals
ax.axhline(y=df1['ShiftedPrice'].mean() + 1.96*np.std(df1['ShiftedPrice'],ddof=1), color='g', linestyle=':', lw=2)
ax.axhline(y=df1['ShiftedPrice'].mean() - 1.96*np.std(df1['ShiftedPrice'],ddof=1), color='g', linestyle=':', lw=2)
plt.show()

我的问题是水平线没有出现 . 相反,我收到以下消息

ax.axhline(y=df1['ShiftedPrice'].mean(), color='r', linestyle='--', lw=2)
Out[22]: <matplotlib.lines.Line2D at 0xccc5c18>