残差图与主图不对齐 [英] Residual plot not aligned with main graph

查看:48
本文介绍了残差图与主图不对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的残差图有什么问题导致与我的主图不对齐?我的代码如下.

将 matplotlib.pyplot 导入为 plt来自 scipy 导入统计将 numpy 导入为 npx = np.array([0.030956,0.032956,0.034956,0.036956,0.038956,0.040956])y = np.array([10.57821088,11.90701212,12.55570876,13.97542486,16.05403248,16.36634177])yerr = [0.101614114,0.363255259,0.057234211,0.09289917,0.093288198,0.420165796]xerr = [0.00021]*len(x)fig1 = plt.figure(1)frame1=fig1.add_axes((.1,.3,.8,.6))m, b = np.polyfit(x, y, 1)打印 'gradient',m,'intercept',bplt.plot(x, m*x + b, '-', color='grey', alpha=0.5)plt.plot(x,y,'.',color='black',markersize=6)plt.errorbar(x,y,xerr=0,yerr=yerr,linestyle="None",color='black')plt.ylabel('$1/sqrt{F}$ $(N)$',fontsize=20)plt.autoscale(enable=True,axis=u'both',tight=True)plt.grid(假)frame2=fig1.add_axes((.1,.1,.8,.2))s = m*x+b #(np.sqrt(4*np.pi*8.85E-12)/2.23E-8)*x差异 = y-splt.plot(x, 差异, 'ro')frame2.set_ylabel('$Residual$',fontsize=20)plt.xlabel('$2s+d_0$$(m)$',fontsize=20)

解决方案

您可以指定轴限制.问题是自动缩放正在以不同的方式移动您的两个图.如果插入 2 行代码,每行都指定轴限制,它将修复它.

plt.axis([.030,.0415, 10, 17]) #line 17plt.axis([.030,.0415, -.6, .8]) #line 26

我相信这就是您要找的.

What is wrong with my residual plot that is causing to not be aligned with my main graph? My code is below.

import matplotlib.pyplot as plt
from scipy import stats
import numpy as np

x = np.array([0.030956,0.032956,0.034956,0.036956,0.038956,0.040956])
y = np.array([10.57821088,11.90701212,12.55570876,13.97542486,16.05403248,16.36634177])
yerr = [0.101614114,0.363255259,0.057234211,0.09289917,0.093288198,0.420165796]
xerr = [0.00021]*len(x)
fig1 = plt.figure(1)
frame1=fig1.add_axes((.1,.3,.8,.6))
m, b = np.polyfit(x, y, 1)
print 'gradient',m,'intercept',b
plt.plot(x, m*x + b, '-', color='grey', alpha=0.5) 
plt.plot(x,y,'.',color='black',markersize=6)
plt.errorbar(x,y,xerr=0,yerr=yerr,linestyle="None",color='black')
plt.ylabel('$1/sqrt{F}$ $(N)$',fontsize=20)
plt.autoscale(enable=True, axis=u'both', tight=True)
plt.grid(False)
frame2=fig1.add_axes((.1,.1,.8,.2))
s = m*x+b #(np.sqrt(4*np.pi*8.85E-12)/2.23E-8)*x
difference = y-s
plt.plot(x, difference, 'ro')
frame2.set_ylabel('$Residual$',fontsize=20)
plt.xlabel('$2s+d_0$ $(m)$',fontsize=20)

解决方案

you can specify the axis limits. the problem is that autoscale is moving your two plots differently. if you insert 2 lines of code, each specifying the axis limits, it will fix it.

plt.axis([.030,.0415, 10, 17])  #line 17
plt.axis([.030,.0415, -.6, .8]) #line 26

i believe this is what you're looking for.

这篇关于残差图与主图不对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆