Python 如何随时间绘制非空值?
我有以下数据帧:Python 如何随时间绘制非空值?,python,pandas,plot,time-series,notnull,Python,Pandas,Plot,Time Series,Notnull,我有以下数据帧: >>> df Qual_B temp_B relhum_B Qual_F temp_F relhum_F Date 1948-01-01 01:00:00 5 -6.0 96 NaN NaN NaN 1948-01-0
>>> df
Qual_B temp_B relhum_B Qual_F temp_F relhum_F
Date
1948-01-01 01:00:00 5 -6.0 96 NaN NaN NaN
1948-01-01 02:00:00 5 -5.3 97 NaN NaN NaN
1948-01-01 03:00:00 5 -4.5 98 NaN 3.5 NaN
1948-01-01 04:00:00 5 -4.3 98 NaN 3.7 NaN
1948-01-01 05:00:00 5 -4.0 99 NaN NaN NaN
>>> test
Qual_B temp_B relhum_B Qual_F temp_F relhum_F
Date
1948-01-01 01:00:00 True True True False False False
1948-01-01 02:00:00 True True True False False False
1948-01-01 03:00:00 True True True False True False
1948-01-01 04:00:00 True True True False True False
1948-01-01 05:00:00 True True True False False False
它表示数据可用性(我用test=pandas.notnull(df)
创建了test
)。我想要一个类似于条形图或堆叠条形图的图,时间在x轴上,列在y轴上,我尝试了以下方法:
fig= plt.figure()
ax = fig.add_subplot(111)
ax.imshow(test.values, aspect='auto', cmap=plt.cm.gray, interpolation='nearest')
但是它没有做任何事情,即使数组的类型与上面的示例完全相同(都是numpy.ndarray)。尝试使用绘制原始数据帧
test.div(test, axis=0).T.plot(kind = 'barh', stacked=True, legend=False, color='b', edgecolor='none')
似乎对于始终存在的值是正确的,但对于部分存在的值则不正确。有人能帮忙吗?假设您使用的是ipython,那么您是使用pylab内联选项启动的吗?(ipython--pylab inline)我已经尝试了inline选项和
%pylab wx
。使用标准spyder控制台,它会产生相同的结果。