在matplotlib中的一个图中包围数据

时间:2016-04-13 19:35:16

标签: python python-2.7 matplotlib

我想在图中的某些数据周围放一个圆圈。我正在使用matplotlib中的函数

    plt.Circle

但它似乎没有用。我使用的代码没有注释掉Circle函数产生图形

[This is a comment

当我删除评论并运行程序时,我得到一个看起来像的图表 我必须手动保存,因为程序不再自行保存。我也得到错误:

    plt.Cirlce((10e2,10e-21),.1, color = 'b', fill = False)
    AttributeError: 'module' object has no attribute 'Cirlce'

我使用的代码是:

    plt.figure()
    plt.subplot(211)
    #plt.Cirlce((10e2,10e-21),.1, color = 'b', fill = False)
    plt.loglog(freqs, np.sqrt(Pxx_H1),'r',label='H1 strain')
    plt.loglog(freqs, np.sqrt(Pxx_L1),'g',label='L1 strain')
    plt.axis([fmin, fmax, 1e-24, 1e-19])
    plt.grid('on')
    plt.ylabel('ASD (strain/rtHz)' , fontsize = 10)
    plt.xlabel('Freq (Hz)' , fontsize = 10)
    plt.tight_layout()
    plt.legend(loc='upper center', prop = {'size':11})
    #plt.suptitle('Gravitational Wave Detection ', fontsize = 10)
    plt.title('Advanced LIGO strain data near GW150914', fontsize = 10)
    #plt.savefig('GW150914_ASDs.png')


    plt.subplot(2,1,2)
    plt.plot(time-tevent,strain_H1_whitenbp,'r',label='H1 strain')
    plt.plot(time-tevent,strain_L1_shift,'g',label='L1 strain')
    plt.plot(NRtime+0.002,NR_H1_whitenbp,'k',label='matched NR waveform')
    plt.text(.1,-5, txt)
    plt.xlim([-0.2,0.05])
    plt.ylim([-4,4])
    plt.xlabel('time (s) since '+str(tevent) , fontsize = 10)
    plt.ylabel('whitented strain' , fontsize = 10)
    plt.tight_layout()
    plt.legend(loc='lower left', prop = {'size':10})
    plt.grid(True)
    #plt.annotate(' Definite Sign ', xy = (0,3), xytext=(-0.08,3), arrowprops=dict(facecolor='black', shrink=0.05))
    #plt.annotate(' Of a Gw', xy = (-.08,2.5))
    plt.title('Advanced LIGO WHITENED strain data near GW150914', fontsize =         10)
    plt.savefig('GW150914_strain_whitened_Example_2.jpg')

如果能够帮助我圈出我想要的数据,我将不胜感激。

编辑:使用@Hun帮助的新图表

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要对轴使用add_artist()方法。所以像这样修改你的脚本。

circle1 = plt.Cirlce((10e2,10e-21),.1, color = 'b', fill = False)
fig = plt.gcf()
fig.gca().add_artist(circle1)
相关问题