簡體   English   中英

在matplotlib中的圖中圈住數據

[英]Encircle Data in a Plot in matplotlib

嗨,我想在繪圖中的某些數據周圍放置一個圓圈。 我正在使用matplotlib中的函數

    plt.Circle

但它似乎不起作用。 我正在使用的代碼沒有注釋掉Circle函數生成圖形

[ 這是一條評論

當我刪除注釋並運行程序時,我得到一個如下圖 我必須手動保存,因為該程序不再單獨保存它。 我也得到錯誤:

    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幫助下的新圖

在此處輸入圖片說明

您需要為軸使用add_artist()方法。 因此,像這樣修改您的腳本。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM