繁体   English   中英

Matplotlib条形图的主要定位器

[英]Matplotlib major locators for bar plot

假设我绘制了一个条形图:

from matplotlib.ticker  import IndexLocator
f , ax = plt.subplots(figsize=(10,5))
ax.bar(x, y, alpha=0.7, align='center')

在此处输入图片说明

如何调整主要定位器的位置,以使每个条形都有一个?

我尝试了:

ax.xaxis.set_major_locator(IndexLocator(x))

但我得到:

TypeError: __init__() missing 1 required positional argument: 'offset'

不知道这是否是正确的方法。

另外,为什么我的条形图之间的间距会变小?

最简单的答案:

plt.xticks( x )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM