Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set limit range (xlim) in python matplotlib?

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

like image 959
Denis Kuzin Avatar asked Dec 24 '22 19:12

Denis Kuzin


1 Answers

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

like image 153
falsetru Avatar answered Mar 04 '23 04:03

falsetru