简体   繁体   English

Matplotlib条形图的主要定位器

[英]Matplotlib major locators for bar plot

Say I plot a bar plot: 假设我绘制了一个条形图:

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

在此处输入图片说明

How can I adjust the location of the major locators so that I have one per bar ? 如何调整主要定位器的位置,以使每个条形都有一个?

I tried with: 我尝试了:

ax.xaxis.set_major_locator(IndexLocator(x))

but I get: 但我得到:

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

Not sure if that is the right way to do it. 不知道这是否是正确的方法。

Also, why is the spacing between my bar plots off? 另外,为什么我的条形图之间的间距会变小?

最简单的答案:

plt.xticks( x )

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

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