我需要用以下字典绘制直方图
x = {5:289, 8:341, 1:1565, 4:655, 2:1337, 9:226, 7:399, 3:967, 6:405}
Run Code Online (Sandbox Code Playgroud)
我需要第一个键从 1 到 9 排序。然后这些值将绘制在直方图中,显示最大概率为 1.0。我尝试了以下(以及其他内容)。
import matplotlib.pyplot as plt
import numpy as np
plt.hist(x.keys(), x.values(), color='g', label = "Real distribution")
plt.show()
Run Code Online (Sandbox Code Playgroud)
或者
plt.hist (x, bins = np.arange(9), color = 'g', label = "Real distribution")
plt.show()
Run Code Online (Sandbox Code Playgroud)
或者
fsn_count_ = sorted(fsn_count)
plt.hist (fsn_count_, bins = np.arange(9), color = 'b', label = "Real distribution")
plt.plot ([0] + bf, color = 'g', label = "Benford Model")
plt.xlabel ('Significant number')
plt.ylabel ('Percentage') …Run Code Online (Sandbox Code Playgroud)