The Python Oracle

Matplotlib autoscale

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping

--

Chapters
00:00 Question
01:11 Accepted answer (Score 13)
01:46 Answer 2 (Score 1)
02:09 Thank you

--

Full question
https://stackoverflow.com/questions/3214...

Answer 1 links:
[Eli Bendersky's Website]: http://eli.thegreenplace.net/
[this post]: http://eli.thegreenplace.net/2008/08/01/.../

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #visualization #matplotlib #plot

#avk47



ACCEPTED ANSWER

Score 12


Not sure if this what you wanted, but I can change it if this was not what you were looking for.

import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection

import pylab as p

fig = plt.figure()
pts1 = []
pts2 = []
for i in range(100):
    pts1.append([i,i])
    pts2.append([-i-3,-i])
lines = LineCollection([pts1,pts2], linestyles='solid')
subplt = fig.add_subplot(111,aspect='equal')
subplt.add_collection(lines)
subplt.autoscale_view(True,True,True)
p.show()

Hope that helps.