我已经在python中绘制了一个带有残差子图的图,并且正在试图找到一种方法,在直方图的末尾绘制残差的直方图。我还想在残差图上添加一个灰色带,显示1个标准差。你知道吗
还有一种方法可以移除地块的顶部和右侧边界。你知道吗
这是我目前拥有的代码和图表的副本。你知道吗
fig1 = pyplot.figure(figsize =(9.6,7.2))
plt.frame1 =fig1.add_axes((0.2,0.4,.75,.6))
pyplot.errorbar(xval, yval*1000, yerr=yerr*1000, xerr=xerr, marker='x', linestyle='None')
# Axis labels
pyplot.xlabel('Height (m)', fontsize = 12)
pyplot.ylabel('dM/dt (g $s^{-1}$)', fontsize = 12)
# Generate best fit line using model function and best fit parameters, and add to plot
fit_line=model_funct(xval, [a_soln, b_soln])
pyplot.plot(xval, fit_line*1000)
# Set suitable axis limits: you will probably need to change these...
#pyplot.xlim(-1, 61)
#pyplot.ylim(65, 105)
# pyplot.show()
plt.frame2 = fig1.add_axes((0.2,0.2,.75,.2)) #start frame1 at 0.2, 0.4
plt.xlabel("Height of Water (m)", fontsize = 12)
plt.ylabel("Normalised\nResiduals", fontsize = 12) #\n is used to start a new line
plt.plot(h,normalised_residuals,"x", color = "green")
plt.axhline(0, linewidth=1, linestyle="--", color="black")
plt.savefig("Final Graph.png", dpi = 500)
代码中的命名有点奇怪,因此我只发布代码片段,因为我自己很难尝试。有时您使用
pyplot
,有时您使用plt
,这应该是相同的。你也应该这样命名你的轴ax = fig1.add_axes((0.2,0.4,.75,.6))
。然后,如果你做了绘图,你应该直接用轴来调用它,即使用ax.errorbar()
。你知道吗要在顶部打印中隐藏轴的边框,请使用:
在底部图中添加一个误差带是非常容易的。用
np.mean()
和np.std()
计算平均值和标准差。之后,打电话改变颜色和alpha值。你知道吗
对于直方图投影,您只需添加另一个轴,就像您之前做过两次一样(假设它被称为
ax
),然后调用在这里,bins必须设置为一个较小的值,因为您没有那么多的数据点。你知道吗
相关问题 更多 >
编程相关推荐