如何使用' add_axes'?
我创建了一个带有一些数据点(蓝色),拟合(紫色)的图,我设法通过使用“ add_axes”来包括拟合的残差(fit-datapoints),如下所示:
#Plot and fit:
fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))
plt.scatter(a/nshots,m/nshots,zorder=-1,s=1)
plt.plot(a/nshots,fit(a/nshots),color='purple')
plt.xlabel(r'$a_i/N_s$ (mV)')
plt.ylabel(r'$m_i/N_s$ (count/$N_s$)')
plt.tick_params(axis='both',which='both',direction='in',right=True,top=True)
#Residuals:
frame2=fig1.add_axes((.1,.1,.8,.2))
plt.scatter(a/nshots,m/nshots-fit(a/nshots),zorder=-1,s=1,color='pink')
plt.xlabel(r'$a_i/N_s$ (mV)')
plt.ylabel(r'residuals')
plt.tick_params(axis='both',which='both',direction='in',right=True,top=True)
但是,我似乎无法对齐结果图上的y标签:
我非常喜欢一种自动对准的方法,我不需要手工对齐标签。
非常感谢您的帮助。
I have created a plot with some data points (in blue), a fit (in purple) and I have managed to include the fit residuals (fit-datapoints) by using 'add_axes' as shown below:
#Plot and fit:
fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))
plt.scatter(a/nshots,m/nshots,zorder=-1,s=1)
plt.plot(a/nshots,fit(a/nshots),color='purple')
plt.xlabel(r'$a_i/N_s$ (mV)')
plt.ylabel(r'$m_i/N_s$ (count/$N_s$)')
plt.tick_params(axis='both',which='both',direction='in',right=True,top=True)
#Residuals:
frame2=fig1.add_axes((.1,.1,.8,.2))
plt.scatter(a/nshots,m/nshots-fit(a/nshots),zorder=-1,s=1,color='pink')
plt.xlabel(r'$a_i/N_s$ (mV)')
plt.ylabel(r'residuals')
plt.tick_params(axis='both',which='both',direction='in',right=True,top=True)
However, I cannot seem to align the y labels on the resulting figure:
I have tried using things like plt.gca().yaxis.set_label_coords(-0.1,0.1) and plt.gca().yaxis.labelpad=20 but I would very much prefer an approach where alignment is automated and I need not align the labels by hand.
Thank you very much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论