我正在研究熱物理項目,爲此我需要比較直方圖和平滑曲線。我的問題是,直方圖被放置到正確的曲線(曲線是一致的打算,雖然酒吧的左上角):Python直方圖位於精確解的右側
我想要的曲線去,雖然的中間酒吧的頂部,就像它應該。它可能看起來很瑣碎,但它真的讓我很不舒服。我希望有一個人可以幫助我!
程序看起來像這樣:
import numpy as np
import matplotlib.pyplot as plt
#--Constants--
M = 20 # Jmax
N = 1000 # Number of J values
T = 50 # Actually T/theta_r
J1 = np.linspace(0,M,N)
J2 = np.linspace(0,M,M+1)
#--Calculate z--
def z(J):
return(2*J+1)*np.exp(-J*(J+1)/T)
#--Plot--
width = .9 #Width of columns
plt.bar(J2, z(J2), width=width) #Plotting histogram
#plt.xticks(ind + width/2, ind) #Replacing the indexes under the columns
plt.plot(J1,z(J1),'-r', linewidth=2)
SZ={'size':'16'}
plt.title('Different terms $z(j)$ plotted as function of $j$',**SZ)
plt.xlabel('$j$',**SZ)
plt.ylabel('$z(j)$',**SZ)
plt.show()
我想這個「問題」連接的方式酒吧被放置!增加粒度並繪製更多條塊,您會看到整個圖片會發生變化,例如試試'width = .7'?進一步說明:用於繪製單個條的數據不是均勻分佈的;根據該點的「.9」範圍內數據的「內部」峯值,您正在繪製的曲線並不完全在條的中間...... – phynfo