[英]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
我正在使用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
我正在使用的代码没有注释掉Circle函数生成图形
[ [
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 编辑:@Hun帮助下的新图
You need to use add_artist() method for axis. 您需要为轴使用add_artist()方法。 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.