Ilja
Ilja

Reputation: 1053

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'

Upvotes: 0

Views: 2291

Answers (2)

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()

Upvotes: 1

Joe S
Joe S

Reputation: 420

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)

Upvotes: 1

Related Questions