简体   繁体   中英

Encircle Data in a Plot in matplotlib

HI I want to place a circle around some data in a plot. I am using the function in matplotlib

    plt.Circle

but it does not seem to be working. The code that am I using is without the commented out Circle function produces the graph

[ 这是一条评论

When I do remove the comment and run the program, I get a graph that looks like Which I have to manually save because the program no longer saves it on its own. I also get the error:

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

The code that I am using is:

    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')

I would appreciate any help in being able to help me circle in the data that I want.

#

Edit: New graph with @Hun help

在此处输入图片说明

You need to use add_artist() method for axis. So modify your script like this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM