简体   繁体   中英

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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