## [Matplotlib-users] Slow drawing of many lines in Basemap

 [Matplotlib-users] Slow drawing of many lines in Basemap From: Zane Selvans - 2008-08-20 23:13:48 ```I'm drawing several hundred lines at a time, each consisting of 10-100 points, and it takes a couple of minutes for them all to display, which makes me think I must be doing something stupid. The function that does the drawing looks like this: def plotlinmap(lins, map=None): if map is None: map = Basemap() map.drawmapboundary(fill_color="white") map.drawmeridians(range(-180,181,30)), labels=[1,0,0,1]) map.drawparallels(range(-90,91,30)), labels=[1,0,0,1]) for lin in lins: x,y = map(degrees(lin.longitudes()),degrees(lin.latitudes())) map.plot(x,y) return(map) It displays one line at a time, whenever map.plot() is called. Really I'd like it to just do all the drawing at the end (assuming that would make the whole process much faster). Is there some way to cleanly pass map.plot() a big list of lines to draw? I'm sure there is and I'm just being dense. Argh. -- Zane Selvans Amateur Earthling http://zaneselvans.org zane@... 303/815-6866 PGP Key: 55E0815F ```

### Thread view

 [Matplotlib-users] Slow drawing of many lines in Basemap From: Zane Selvans - 2008-08-20 23:13:48 ```I'm drawing several hundred lines at a time, each consisting of 10-100 points, and it takes a couple of minutes for them all to display, which makes me think I must be doing something stupid. The function that does the drawing looks like this: def plotlinmap(lins, map=None): if map is None: map = Basemap() map.drawmapboundary(fill_color="white") map.drawmeridians(range(-180,181,30)), labels=[1,0,0,1]) map.drawparallels(range(-90,91,30)), labels=[1,0,0,1]) for lin in lins: x,y = map(degrees(lin.longitudes()),degrees(lin.latitudes())) map.plot(x,y) return(map) It displays one line at a time, whenever map.plot() is called. Really I'd like it to just do all the drawing at the end (assuming that would make the whole process much faster). Is there some way to cleanly pass map.plot() a big list of lines to draw? I'm sure there is and I'm just being dense. Argh. -- Zane Selvans Amateur Earthling http://zaneselvans.org zane@... 303/815-6866 PGP Key: 55E0815F ```
 Re: [Matplotlib-users] Slow drawing of many lines in Basemap From: Jeff Whitaker - 2008-08-22 12:08:52 ```Zane Selvans wrote: > I'm drawing several hundred lines at a time, each consisting of 10-100 > points, and it takes a couple of minutes for them all to display, > which makes me think I must be doing something stupid. > > The function that does the drawing looks like this: > > def plotlinmap(lins, map=None): > if map is None: > map = Basemap() > > map.drawmapboundary(fill_color="white") > map.drawmeridians(range(-180,181,30)), labels=[1,0,0,1]) > map.drawparallels(range(-90,91,30)), labels=[1,0,0,1]) > > for lin in lins: > x,y = map(degrees(lin.longitudes()),degrees(lin.latitudes())) > map.plot(x,y) > > return(map) > > It displays one line at a time, whenever map.plot() is called. Really > I'd like it to just do all the drawing at the end (assuming that would > make the whole process much faster). Is there some way to cleanly > pass map.plot() a big list of lines to draw? I'm sure there is and > I'm just being dense. Argh. > > -- > Zane Selvans > Amateur Earthling > http://zaneselvans.org > zane@... > 303/815-6866 > PGP Key: 55E0815F > > Zane: You can set up a LineCollection like this lcoll = LineCollection(segments) then add it to the current axes ax = pylab.gca() ax.add_collection(lcoll) (instead of using the Basemap plot method). To make sure the map axes are rescaled properly, you may need to do map.set_axes_limits() afterwards. See the line_collection.py pylab example for more details. -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 ```
 Re: [Matplotlib-users] Slow drawing of many lines in Basemap From: Zane Selvans - 2008-08-25 16:45:52 ```On Aug 22, 2008, at 5:08 AM, Jeff Whitaker wrote: > Zane Selvans wrote: >> I'm drawing several hundred lines at a time, each consisting of >> 10-100 points, and it takes a couple of minutes for them all to >> display, which makes me think I must be doing something stupid. >> > Zane: You can set up a LineCollection like this > > lcoll = LineCollection(segments) > > then add it to the current axes > > ax = pylab.gca() > ax.add_collection(lcoll) > > (instead of using the Basemap plot method). It turned out that just adding: interactive(False) before the drawing loop, and show() after it, sped things up tremendously. Instead of 5 minutes, it now takes about 2 seconds for the map to render. Which, ironically, is much more "interactive" :) Thanks for the pointer to LineCollection though. I'd never seen that. Zane -- Zane Selvans Amateur Earthling http://zaneselvans.org zane@... 303/815-6866 PGP Key: 55E0815F ```

## Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks