On Wed, Jul 13, 2011 at 6:49 PM, Benjamin Root <ben.r...@ou.edu> wrote:
> On Wednesday, July 13, 2011, Justin McCann <jne...@gmail.com> 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
====

------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to