From: Justin M. <jn...@gm...> - 2011-07-14 15:06:37
|
On Wed, Jul 13, 2011 at 6:49 PM, Benjamin Root <ben...@ou...> wrote: > On Wednesday, July 13, 2011, Justin McCann <jn...@gm...> wrote: >> $ ipython -pylab >> # ==== >> from matplotlib.collections import LineCollection >> f = figure() >> plot() >> ax = gca() >> vec = numpy.random.random((10,3)) >> segs = [] >> for i in range(0, len(vec)): >> x1 = vec[i][0] >> #x1 = 3000000 >> x2 = vec[i][1] >> #x2 = 4000000 >> y1 = y2 = vec[i][2] >> segs.extend( [[(x1,y1),(x2,y2)]] ) >> >> line_segments = LineCollection(segs, linewidth=3, alpha=0.3, colors = >> 'r', linestyle = 'solid') >> ax.add_collection(line_segments) >> ax.set_xlim(0,1) >> ax.set_ylim(0,1) >> show() # hmmmm... nothing yet >> draw() # force a draw; now it works >> ... > Just an observation (I haven't tested anything)... But what is up with > the call to plot()? It might be causing issues with the autoscaler. > Any line collections created without other plotting functions is going > to need the axes limits set. > > Ben Root > Yeah, that was weird. :) I added that when I was first messing around, and the axes didn't show up even when I called show(). If you do the draw() at the end, then you don't need to call plot(), and then you also don't need to mess with the view limits (set_{x,y}lim). I guess the moral of the story is, "if you don't explicitly plot() [or a variant], you must explicitly draw()." === from matplotlib.collections import LineCollection f = figure() ax = gca() vec = numpy.random.random((10,3)) segs = [] for i in range(0, len(vec)): x1 = vec[i][0] x2 = vec[i][1] y1 = y2 = vec[i][2] segs.extend( [[(x1,y1),(x2,y2)]] ) line_segments = LineCollection(segs, linewidth=3, alpha=0.3, colors='r', linestyle='solid') ax.add_collection(line_segments) draw() # force a draw; now it works ==== |