需要使用熊猫系列和numpy数组创建图

时间:2019-04-27 10:16:57

标签: python matplotlib

我有一个熊猫时间序列(x),时间索引为t,长度为numpy数组(y)。我需要在y轴上绘制x,y和在x轴上绘制时间(t)。

x.shape (320,)    
y.shape (320,1)

我尝试转换numpy数组,但它给我一个错误(数据必须为一维)。

pd.Series(y,index=x.index)

1 个答案:

答案 0 :(得分:1)

假设您的x是熊猫系列,而y是一个numpy数组

import matplotlib.pyplot as plt
plt.figure()
plt.plot(x.index.values, y, label="y")
plt.plot(x.index.values, x.value, label="x")
plt.legend()
plt.show()