我正在matplotlib中创建一个条形图,其中有很多非常窄的条形图。下面是一些示例代码:import matplotlib.pyplot as plt
import numpy as np
x = np.arange(100)
y = np.random.poisson(1, size=100)
fig, ax = plt.subplots(figsize=(8, 1))
ax.bar(x, y, width=1, facecolor='red', edgecolor='white', linewidth=1)
ax.grid(color='white', linewidth=1, linestyle='-')
# some plot aesthetics
for spine in ['right', 'top', 'left']:
ax.spines[spine].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('none')
ax.yaxis.set_major_locator(plt.MultipleLocator(1))
ax.yaxis.set_major_formatter(plt.NullFormatter())

请注意,由于像素分辨率有限,条形图在渲染宽度上有明显变化。在
在matplotlib中创建此绘图的最佳方法是什么,同时确保渲染结果具有等宽的条形图?在
918

被折叠的 条评论
为什么被折叠?



