简体   繁体   中英

Python - Barchart in Matplotlib - How to change X axis

simple, probably dummy question, but I can't find the answer:

How to adjust the X axis for a bar plot in Matplotlib?

my code so far:

_ = matplotlib.pyplot.bar(names, value, color="blue")
_.axis([-11,11,0,1])

returns --> AttributeError: 'BarContainer' object has no attribute 'axis'

You can use xlim for this!

https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlim.html

Example:

import matplotlib.pyplot as plt
plt.xlim(-11, 11)

First of all a good practise to make things easier is to import this:

import matplotlib.pyplot as plt

and then you can simply

plt.bar(names, value, color="blue")
plt.xlim([-11,11])

plt.show()

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