python - 不明白为什么 matplotlib 条形宽度不恒定
问题描述
嗨,我想有很多关于这个的帖子。但我无法真正理解发生了什么。基于其他堆栈溢出问题,我猜测我的条形图宽度不恒定的原因是由于“非线性轴?”
我真的不明白为什么这会导致我的 matplotlib barplot 宽度不一样:
# Initialize Data Frame
df = pd.DataFrame({r'$l$': range(1,4)}, index = range(1, 4))
# Add other stuff
df[r'Frequency (emitted photon) / $\frac{k_B \Theta_R}{h}$'] = (df[r'$l$'] * (df[r'$l$'] + 1) -
(df[r'$l$'] - 2)*(df[r'$l$'] - 1))
df[r'Probabilities $p(l)$'] = (np.exp((-df[r'$l$']/300) * (df[r'$l$'] + 1)) /
(((2*df[r'$l$'] + 1) * np.exp((-df[r'$l$']/300) * (df[r'$l$'] + 1))) +
((2 * df[r'$l$'] - 1) * np.exp(-((df[r'$l$'] - 2)/300) * (df[r'$l$'] - 1)))
))
# Graph Settings
fig, axes = plt.subplots(nrows = 1, ncols = 1, figsize = (16,8))
axes.bar(df[r'Frequency (emitted photon) / $\frac{k_B \Theta_R}{h}$'],
df[r'Probabilities $p(l)$'], label = 'Probability vs Frequency', color = 'red', width = 0.1)
# Graph Settings
axes.set_title('Probabilities against frequency(emitted photon)', fontsize = 20)
axes.xaxis.set_ticks(range(0, 13))
# Display Graph
plt.show()
即使我将宽度设置为 0.1,条形图也非常难看
为什么第一个条的宽度还可以,但其余的那么胖?我如何纠正它以使所有宽度都相同?
解决方案
推荐阅读
- sql - 如何从 SQL Server 中的另一个表中选择“组”列名?
- github - 如何在 Github 中隐藏特定的重复更改?
- jenkins - 如何在一个文件中编写多个函数?
- javascript - TypeError: role.setPermissions 不是一个函数,即使 TypeScript 说它是
- reactjs - React 分页组件搜索问题
- .net - Dotnet:Dockerfile 没有这样的文件或目录 Blazor
- ruby-on-rails - 是否可以在观察者中使用回调条件?
- reverse-proxy - bazel + angular项目的反向代理
- javascript - Chromium Audio Worklet 辍学。一些最初,然后偶尔以 30 秒为间隔
- python - 使用 imaplib 的 Python 脚本偶尔会失败