matplotlib - 直方图的最后一个 bin 缺失
问题描述
首先,这个答案对我不起作用,但问题本质上是一样的。我的数据x
是 [-2:18] 范围内的列表,标记为 [A:U]。最后一个 bin(17 或 T)实际上是在累积 17-T 和 18-U 的值的数量,显示 bin 18-U 为空。
我的代码看起来像这样(美学已被省略,x
是从 .csv 读取的):
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=figsize)
Labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U']
bins = len(Labels)
ax.hist(x, bins=bins, density=False, histtype='step', color='grey', linewidth=2)
ax.set_xticklabels(Labels)
plt.show()
结果是这样的:
尝试现有的解决方案,bins = len(Labels) + 1
没有任何区别。
解决方案
推荐阅读
- reactjs - React Boostrap 选项卡不显示选项卡内容
- powershell - 具有相同事件 ID 的两个不同事件
- python - 如何在 Tkinter GUI 中实现打字模式?
- java - 删除文件中的 n 行
- apache-spark - spark连接到端口8020而不是9000并且连接被拒绝
- rust - 在匹配中分配向量的值:移动发生......它没有实现“复制”特征
- typescript - 推断多个泛型函数的签名
- python - 没有名为“odbAccess”的模块 python abaqus 脚本
- android - Android:如何在进度条中结束进度?
- delphi - Delphi - 声音变化通知(静音/取消静音)