Python pandas用数据点绘制线图

时间:2017-11-09 07:57:02

标签: python pandas matplotlib plot

我想根据列A绘制线图。基于列sig我想在图表A中添加一些标记:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data = pd.DataFrame(np.random.randn(120), columns=list('A'))

data['sig'] =   np.NaN
data['sig'] =  np.where((data['A'] > 1),      data['A'], data['sig'] )

data.plot(grid=True)
plt.show()

我尝试将markevery=data['sig']添加到plot()语句中,但它给了我几个错误。任何提示?

1 个答案:

答案 0 :(得分:0)

为什么不直接在matplotlib中绘图?

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data = pd.DataFrame(np.random.randn(120), columns=list('A'))

data['sig'] =   np.NaN
data['sig'] =  np.where((data['A'] > 1),      data['A'], data['sig'] )

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(data["A"])
ax.scatter(data.index, data["sig"])