未出现在python绘图上的数据

未出现在python绘图上的数据,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有一个数据框架,日期作为索引,浮动作为列,填充的大部分是NaN和一些浮动 我正在使用以下方法绘制此数据帧: fig, ax = plt.subplots() plot(df2[11][2:], linestyle='dashed',linewidth=2,label='xx') ax.set(xlabel='xx', ylabel='xx', title='xx') ax.grid() ax.legend() 绘图窗口打开,但没有显示任何数据。但是如果我使用标记而不是直线,数据点就会出现 我

我有一个数据框架,日期作为索引,浮动作为列,填充的大部分是NaN和一些浮动

我正在使用以下方法绘制此数据帧:

fig, ax = plt.subplots()
plot(df2[11][2:], linestyle='dashed',linewidth=2,label='xx')
ax.set(xlabel='xx', ylabel='xx', title='xx')
ax.grid()
ax.legend()
绘图窗口打开,但没有显示任何数据。但是如果我使用标记而不是直线,数据点就会出现

我应该更正什么以将图形绘制为直线

编辑谢谢,它是这样工作的:

s1 = np.isfinite(df2[11][2:])
fig, ax = plt.subplots()
plot(df2.index[2:][s1],df2[11][2:].values[s1], linestyle='-',linewidth=2,label='xx')
ax.set(xlabel='xx', ylabel='xx',title='xx')
ax.grid()
ax.legend()

在您的情况下,matplotlib不会在由NaN分隔的点之间绘制线。你可以掩盖南部或摆脱他们。请看下面的链接,这里有一些跳过NaN的解决方案

试试看

import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot(df2[11][2:], linestyle='dashed',linewidth=2,label='xx')
plt.set(xlabel='xx', ylabel='xx', title='xx')
plt.grid()
plt.legend()
plt.show()