假设我有多个时间相关的变量,我想将它们一起堆积在一起,如下图所示,我将如何在matplotlib中这样做?目前,当我尝试绘制它们时,它们显示为多个独立的图。
编辑: 我有一个Pandas数据帧,K列对应于因变量,N行对应于那些K变量的观察值。
示例代码:
df = get_representation(mat) #df is the Pandas dataframe
for i in xrange(len(df.columns)):
plt.plot(df.ix[:,i])
plt.show()
我想把它们全部放在另一个上面。
答案 0 :(得分:1)
您可以通过垂直移动每条曲线来堆叠所有曲线:
df = get_representation(mat) #df is the Pandas dataframe
for i in xrange(len(df.columns)):
plt.plot(df.ix[:, i] + shift*i)
plt.show()
此处shift
表示曲线之间的平均距离。