在python中添加\u subplot()+groupby()+买卖信号

2024-04-26 13:19:45 发布

您现在位置:Python中文网/ 问答频道 /正文

不幸的是,我无法在groupby中绘制出每个组的短信号和长信号。 请帮助我:

grouped = df4.groupby('T')
for name, group in grouped:
    df12=df4.C[df4.diffpos== 1.0]
    fig=plt.figure()
    ax1=fig.add_subplot(111, label=name)
    group.plot(y=['C'],ax=ax1, color='r', lw=2.,figsize=(10,10))
    ax1.plot(df12,'^', markersize=10, color='m',label='Buy')
    ax.plot(df4.C[df4.diffpos== -1.0], 'v', markersize=10, color='k',label='Sell')
    plt.legend(loc = 'best')
    plt.title(name)
plt.show()

enter image description here


Tags: nameplotgroupfigpltaxlabelcolor