使用单个x轴堆叠多个图

时间:2014-11-17 22:13:37

标签: matplotlib

假设我有多个时间相关的变量,我想将它们一起堆积在一起,如下图所示,我将如何在matplotlib中这样做?目前,当我尝试绘制它们时,它们显示为多个独立的图。 enter image description here

编辑: 我有一个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() 

我想把它们全部放在另一个上面。

1 个答案:

答案 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表示曲线之间的平均距离。