4

Why doesn't matplotlib.pyplot.xlim() method work in the below example?

import matplotlib.pyplot as plt
l = [0,0.2,0.4,0.6,0.8,1.0]
plt.plot(l,l)
plt.xlim = (-10,10)
plt.show()

chart

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Denis Kuzin
  • 863
  • 2
  • 10
  • 18

2 Answers2

8

matplotlib.pyplot.xlim, matplotlib.pyplot.ylim are functions. You should call them instead of assigning to them:

plt.ylim(-10,10)
plt.xlim(-10,10)

enter image description here

falsetru
  • 357,413
  • 63
  • 732
  • 636
3

plt.xlim is a function. Instead of changing this function, you need to use it by calling it with the respective limits.

plt.xlim((-10,10))
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712