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

Denis Kuzin
  • 823
  • 1
  • 9
  • 18
  • 1
    Possible duplicate of [Python, Matplotlib, subplot: How to set the axis range?](https://stackoverflow.com/questions/2849286/python-matplotlib-subplot-how-to-set-the-axis-range) – Denis Kuzin Sep 28 '18 at 10:33

2 Answers2

7

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
  • 336,967
  • 57
  • 673
  • 597
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
  • 289,005
  • 45
  • 571
  • 615