如何使用直方图绘制状态DOS的密度?

时间:2019-05-13 08:01:51

标签: python python-3.x numpy matplotlib physics

我想使用直方图绘制状态密度(DOS)。 Dos定义为单位能量$dN/dE$中的状态数。我有能量值。 DOS图以b / w能量(在x轴上)和DOS(在y轴上)绘制。 DOS的单位为1 /能量。但是直方图是无单位的,但是我想在y轴上获得1 /能量的单位。如果我将每个容器的计数除以它们各自的容器宽度,在直方图的情况下,我可以得到1 /能量的单位吗?

`E = np.array([-1.61032636, -1.23577245, -0.50587484, -0.28348457, 
                 -0.18748945,  0.4537447,   1.2338455,   2.13535718])

n,bins,patches = plt.hist(E,bins=4)
print("n: ",n)
print("bins: ",bins)
plt.savefig("./DOS")`

1 个答案:

答案 0 :(得分:0)

当您决定绘制直方图时,您希望绘制间隔中包含的所有值。据我了解,您想根据e列表计算所有Data值。如果您不清楚,请查看here

Data将定义您要计算e值的间隔。 bin参数(doc)为您提供了这种可能性。 对数据进行排序也“更好”。如果不对Data进行排序,则意味着间隔可以重叠,并且可以在多个间隔中计数值。 (如果不对它进行排序,它将起作用。我不确定这是否是您想要的,取决于您的工作)。在这里,我对Data进行了排序。您可以两者都尝试!

这里有个例子:

# Import module
import numpy as np
import matplotlib.pyplot as plt
Data = np.array([-1.61032636, -1.23577245, -0.50587484, -0.28348457,
                 -0.18748945, 0.4537447, 1.2338455, 2.13535718])
Data.sort()
print(Data)
# [-1.61032636 - 1.23577245 - 0.50587484 - 0.28348457 - 0.18748945  0.4537447
#   1.2338455    2.13535718]

# Just in order you get the same plot
np.random.seed(2019)
# Assuming e is define as bellow
e = (np.random.rand(50) - 0.5) * 2
print(e)
# [ 0.80696443 -0.21383899  0.24793992  0.2757548   0.76099814 -0.40165596
#   0.40439654  0.80641232  0.76276385 -0.1885004  -0.09510676 -0.46585935
#  -0.67427026  0.77842939 -0.70304755  0.96944697 -0.93527756  0.03070151
#  -0.59774191  0.77202175  0.02723984  0.15660317 -0.40143469  0.67439481
#   0.05329966 -0.79031152 -0.44374118 -0.90681013  0.0181523  -0.05514742
#   0.80897467  0.88698444  0.4067847   0.69259591  0.85598929  0.63872377
#   0.69037113  0.58290375 -0.65799968 -0.42004416 -0.39103217 -0.70467981
#   0.14763706  0.72711402 -0.35340105 -0.44870115  0.36437477 -0.61718738
#   0.16204896  0.72511654]


# Build the histogram
n, bins, patches = plt.hist(e, bins=Data )

print("n: ", n)
print("bins: ", bins)

# Show the histogram
plt.show()

enter image description here