我有从0
到n
(包括在内)的整数值,我想用正确的x轴标签绘制一个n+1
条形图。这是我的尝试。
import numpy as np
import matplotlib.pyplot as plt
# Generate integer values
n = 20
values = np.random.randint(low=0, high=(n+1), size=1000)
# Plot histogram
fig, ax = plt.subplots(figsize=(20, 4))
_, bins, _ = ax.hist(values, bins=n+1, edgecolor='k', color='lightsalmon')
ax.set_xticks(bins)
ax.set_xticklabels(bins.astype(int))
plt.show()
字符串
这几乎是正确的,但x轴看起来很奇怪。
的数据
1条答案
按热度按时间798qvoo81#
这个应该可以了
字符串