Aalok kapoor | 1 Dec 05:52
Picon
Favicon

Re: Memory leaks in Basemap

Thanks for reply,

This was just an example for mem leak  in my application. Actually i want maps with different data to be loaded each time and the map objects taken once changees after ploting so i have to take different object each time. After around 20 maps generation it gives memory error to me.

thanks,
-Aalok

Jeff Whitaker <jswhit-97jfqw80gc6171pxa8y+qA@public.gmane.org> wrote:

Aalok kapoor wrote:
> Hi all,
>
> I am using matplotlib-0.87.7, Basemap-0.9.3, Numpy-1.1 and agg backend.
> I am facing memory leak problems after running following script -
>
>
> import os, sys, time
> import cStringIO
> import Image
> import matplotlib
> matplotlib.use('Agg')
>
> import matplotlib.pylab as p
> import matplotlib.numerix as nx
> from matplotlib.toolkits.basemap import Basemap
>
> def get_image_bytes(width_fig, height_fig, str_img):
> """Returns the bytes representing the image generated
>
> The createImage method should be called before calling this method.
>
> :Returns:
> Byte data.
> """
> # Get the actual image data
> f = cStringIO.StringIO()
> dims = (width_fig, height_fig)
> im = Image.fromstring("RGB", dims, str_img)
> im.save(f, "JPEG")
> return f.getvalue()
>
> def report_memory(i):
> pid = os.getpid()
> a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
> print i, ' ', a2[1],
> return int(a2[1].split()[1])
>
>
>
> # take a memory snapshot on indStart and compare it with indEnd
> indStart, indEnd = 30, 150
> print ' rss vsz %mem'
> for i in range(indEnd):
> p.figure(figsize=(float(640)/80.0,float(480)/80.0),
> facecolor='w', edgecolor='w')
> p.axes([0.0, 0.0, 1.0, 1.0])
> map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
> area_thresh=1000.)
> # draw coastlines, country boundaries, fill continents.
> map1.drawcoastlines(linewidth=.5)
> map1.drawcountries()
> map1.fillcontinents(color="#CEFFCE")
> # draw the edge of the map projection region (the projection limb)
> map1.drawmapboundary()
> # compute the native map projection coordinates for cities.
> lats, lons = ([18.728], [20.890])
> x,y = map1(lons,lats)
> # plot filled circles at the locations of the cities.
> map1.plot(x,y,'bo')
> canvas = p.get_current_fig_manager().canvas
> agg = canvas.switch_backends \
> (matplotlib.backends.backend_agg.FigureCanvasAgg)
> agg.draw() # Takes ~.9 seconds
> # get the image data
> str_img = agg.tostring_rgb()
> width_fig, height_fig = map(int, agg.figure.bbox.get_bounds()[2:])
> p.cla()
> p.close()
> bytes = get_image_bytes(width_fig, height_fig, str_img)
>
>
> val = report_memory(i)
> # wait a few cycles for memory usage to stabilize
> if i==indStart: start = val
>
> end = val
> print 'Average memory consumed per loop: %1.4fk bytes' % \
> ((end-start)/float(indEnd-indStart))
>
>
>
>
> Here is the O/P
>
> $python memory_leak_map.py
> rss vsz %mem
> 0 47272 50632 9.7
> 1 74412 77700 15.3
> 2 93960 97380 19.3
> 3 113308 116776 23.3
> 4 132824 136416 27.3
> 5 152352 155828 31.3
> 6 171860 175216 35.3
> 7 191372 194868 39.3
> 8 210872 214248 43.3
> 9 230336 233916 47.3
> 10 249732 253284 51.3
> 11 269252 272692 55.3
> 12 288680 292336 59.3
> 13 308108 311724 63.2
> 14 305160 331112 62.6
> 15 301096 350764 61.8
> 16 304884 370160 62.6
> 17 298276 389804 61.2
> 18 305876 409184 62.8
> 19 298316 428596 61.2
> 20 307856 448224 63.2
> 21 308004 467640 63.2
> 22 308844 487016 63.4
> 23 306260 506656 62.9
> 24 300612 526052 61.7
> Traceback (most recent call last):
> File "memory_leak_map.py", line 41, in ?
> area_thresh=1000.)
> File
> "/usr/local/lib/python2.4/site-packages/matplotlib/toolkits/basemap/basemap.py",
> line 815, in __init__
> self.riversegs = segments+segments2+segments3
> MemoryError
> Killed: 9
>
>
> Can someone please help me out solving this problem?
>
>
> Thanks
> -Aalok
>
Aaolk: All your plots use the same map projection, yet you are
initializing a new Basemap instance every time through the loop. Try
moving the line

map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
area_thresh=1000.)

outside the loop.

-Jeff

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker-32lpuo7BZBA@public.gmane.org
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg


Find out what India is talking about on - Yahoo! Answers India
Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Jeff Whitaker | 1 Dec 14:27
Favicon

Re: Memory leaks in Basemap

Aalok kapoor wrote:
> Thanks for reply,
>
> This was just an example for mem leak  in my application. Actually i 
> want maps with different data to be loaded each time and the map 
> objects taken once changees after ploting so i have to take different 
> object each time. After around 20 maps generation it gives memory 
> error to me.
>
> thanks,
> -Aalok
>
> */Jeff Whitaker <jswhit@...>/* wrote:
>
>     Aalok kapoor wrote:
>     > Hi all,
>     >
>     > I am using matplotlib-0.87.7, Basemap-0.9.3, Numpy-1.1 and agg
>     backend.
>     > I am facing memory leak problems after running following script -
>     >
>     >
>     > import os, sys, time
>     > import cStringIO
>     > import Image
>     > import matplotlib
>     > matplotlib.use('Agg')
>     >
>     > import matplotlib.pylab as p
>     > import matplotlib.numerix as nx
>     > from matplotlib.toolkits.basemap import Basemap
>     >
>     > def get_image_bytes(width_fig, height_fig, str_img):
>     > """Returns the bytes representing the image generated
>     >
>     > The createImage method should be called before calling this method.
>     >
>     > :Returns:
>     > Byte data.
>     > """
>     > # Get the actual image data
>     > f = cStringIO.StringIO()
>     > dims = (width_fig, height_fig)
>     > im = Image.fromstring("RGB", dims, str_img)
>     > im.save(f, "JPEG")
>     > return f.getvalue()
>     >
>     > def report_memory(i):
>     > pid = os.getpid()
>     > a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
>     > print i, ' ', a2[1],
>     > return int(a2[1].split()[1])
>     >
>     >
>     >
>     > # take a memory snapshot on indStart and compare it with indEnd
>     > indStart, indEnd = 30, 150
>     > print ' rss vsz %mem'
>     > for i in range(indEnd):
>     > p.figure(figsize=(float(640)/80.0,float(480)/80.0),
>     > facecolor='w', edgecolor='w')
>     > p.axes([0.0, 0.0, 1.0, 1.0])
>     > map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
>     > area_thresh=1000.)
>     > # draw coastlines, country boundaries, fill continents.
>     > map1.drawcoastlines(linewidth=.5)
>     > map1.drawcountries()
>     > map1.fillcontinents(color="#CEFFCE")
>     > # draw the edge of the map projection region (the projection limb)
>     > map1.drawmapboundary()
>     > # compute the native map projection coordinates for cities.
>     > lats, lons = ([18.728], [20.890])
>     > x,y = map1(lons,lats)
>     > # plot filled circles at the locations of the cities.
>     > map1.plot(x,y,'bo')
>     > canvas = p.get_current_fig_manager().canvas
>     > agg = canvas.switch_backends \
>     > (matplotlib.backends.backend_agg.FigureCanvasAgg)
>     > agg.draw() # Takes ~.9 seconds
>     > # get the image data
>     > str_img = agg.tostring_rgb()
>     > width_fig, height_fig = map(int, agg.figure.bbox.get_bounds()[2:])
>     > p.cla()
>     > p.close()
>     > bytes = get_image_bytes(width_fig, height_fig, str_img)
>     >
>     >
>     > val = report_memory(i)
>     > # wait a few cycles for memory usage to stabilize
>     > if i==indStart: start = val
>     >
>     > end = val
>     > print 'Average memory consumed per loop: %1.4fk bytes' % \
>     > ((end-start)/float(indEnd-indStart))
>     >
>     >
>     >
>     >
>     > Here is the O/P
>     >
>     > $python memory_leak_map.py
>     > rss vsz %mem
>     > 0 47272 50632 9.7
>     > 1 74412 77700 15.3
>     > 2 93960 97380 19.3
>     > 3 113308 116776 23.3
>     > 4 132824 136416 27.3
>     > 5 152352 155828 31.3
>     > 6 171860 175216 35.3
>     > 7 191372 194868 39.3
>     > 8 210872 214248 43.3
>     > 9 230336 233916 47.3
>     > 10 249732 253284 51.3
>     > 11 269252 272692 55.3
>     > 12 288680 292336 59.3
>     > 13 308108 311724 63.2
>     > 14 305160 331112 62.6
>     > 15 301096 350764 61.8
>     > 16 304884 370160 62.6
>     > 17 298276 389804 61.2
>     > 18 305876 409184 62.8
>     > 19 298316 428596 61.2
>     > 20 307856 448224 63.2
>     > 21 308004 467640 63.2
>     > 22 308844 487016 63.4
>     > 23 306260 506656 62.9
>     > 24 300612 526052 61.7
>     > Traceback (most recent call last):
>     > File "memory_leak_map.py", line 41, in ?
>     > area_thresh=1000.)
>     > File
>     >
>     "/usr/local/lib/python2.4/site-packages/matplotlib/toolkits/basemap/basemap.py",
>
>     > line 815, in __init__
>     > self.riversegs = segments+segments2+segments3
>     > MemoryError
>     > Killed: 9
>     >
>     >
>     > Can someone please help me out solving this problem?
>     >
>     >
>     > Thanks
>     > -Aalok
>     >
>     Aaolk: All your plots use the same map projection, yet you are
>     initializing a new Basemap instance every time through the loop. Try
>     moving the line
>
>     map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
>     area_thresh=1000.)
>
>     outside the loop.
>
>     -Jeff
>

Aaolk:  Here's what I get with matplotlib 0.87.7, basemap 0.9.4, numpy 
1.0 on MacOS 10.4.9 with python 2.5 (python 2.4 gives the same result):

[mac28:~/matplotlib/toolkits/basemap] jsw% python memleak.py
 rss vsz %mem
0    28248   153200 -1.3
1    34028   157316 -1.6
2    34908   158084 -1.7
3    35688   158852 -1.7
4    36200   159364 -1.7
5    36712   159876 -1.8
6    36456   159620 -1.7
7    36712   159876 -1.8
8    36712   159876 -1.8
9    36712   159876 -1.8
10    36712   159876 -1.8
11    36712   159876 -1.8
12    36456   159620 -1.7
13    36712   159876 -1.8
14    36712   159876 -1.8
15    36712   159876 -1.8
16    36712   159876 -1.8
17    36712   159876 -1.8
18    36712   159876 -1.8
19    36712   159876 -1.8
20    36712   159876 -1.8
21    36712   159876 -1.8

The %mem flag doesn't appear to work right on MacOS X, but otherwise it 
looks fine - no memory leak.  I see you are using a pre-release version 
of numpy - I wonder if that could be the problem?

-Jeff

--

-- 
Jeffrey S. Whitaker         Phone : (303)497-6313
NOAA/OAR/CDC  R/PSD1        FAX   : (303)497-6449
325 Broadway                Boulder, CO, USA 80305-3328

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Aalok kapoor | 1 Dec 14:36
Picon
Favicon

Re: Memory leaks in Basemap

Hi,

Thanks for this direction. I am using Numpy-1.1. Do I not supposed to use this version? I will try to use older version and see what happens. I hope this will solve the problem.

thanks
-Aalok

Jeff Whitaker <jswhit-97jfqw80gc6171pxa8y+qA@public.gmane.org> wrote:

Aalok kapoor wrote:
> Thanks for reply,
>
> This was just an example for mem leak in my application. Actually i
> want maps with different data to be loaded each time and the map
> objects taken once changees after ploting so i have to take different
> object each time. After around 20 maps generation it gives memory
> error to me.
>
> thanks,
> -Aalok
>
> */Jeff Whitaker /* wrote:
>
> Aalok kapoor wrote:
> > Hi all,
> >
> > I am using matplotlib-0.87.7, Basemap-0.9.3, Numpy-1.1 and agg
> backend.
> > I am facing memory leak problems after running following script -
> >
> >
> > import os, sys, time
> > import cStringIO
> > import Image
> > import matplotlib
> > matplotlib.use('Agg')
> >
> > import matplotlib.pylab as p
> > import matplotlib.numerix as nx
> > from matplotlib.toolkits.basemap import Basemap
> >
> > def get_image_bytes(width_fig, height_fig, str_img):
> > """Returns the bytes representing the image generated
> >
> > The createImage method should be called before calling this method.
> >
> > :Returns:
> > Byte data.
> > """
> > # Get the actual image data
> > f = cStringIO.StringIO()
> > dims = (width_fig, height_fig)
> > im = Image.fromstring("RGB", dims, str_img)
> > im.save(f, "JPEG")
> > return f.getvalue()
> >
> > def report_memory(i):
> > pid = os.getpid()
> > a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
> > print i, ' ', a2[1],
> > return int(a2[1].split()[1])
> >
> >
> >
> > # take a memory snapshot on indStart and compare it with indEnd
> > indStart, indEnd = 30, 150
> > print ' rss vsz %mem'
> > for i in range(indEnd):
> > p.figure(figsize=(float(640)/80.0,float(480)/80.0),
> > facecolor='w', edgecolor='w')
> > p.axes([0.0, 0.0, 1.0, 1.0])
> > map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
> > area_thresh=1000.)
> > # draw coastlines, country boundaries, fill continents.
> > map1.drawcoastlines(linewidth=.5)
> > map1.drawcountries()
> > map1.fillcontinents(color="#CEFFCE")
> > # draw the edge of the map projection region (the projection limb)
> > map1.drawmapboundary()
> > # compute the native map projection coordinates for cities.
> > lats, lons = ([18.728], [20.890])
> > x,y = map1(lons,lats)
> > # plot filled circles at the locations of the cities.
> > map1.plot(x,y,'bo')
> > canvas = p.get_current_fig_manager().canvas
> > agg = canvas.switch_backends \
> > (matplotlib.backends.backend_agg.FigureCanvasAgg)
> > agg.draw() # Takes ~.9 seconds
> > # get the image data
> > str_img = agg.tostring_rgb()
> > width_fig, height_fig = map(int, agg.figure.bbox.get_bounds()[2:])
> > p.cla()
> > p.close()
> > bytes = get_image_bytes(width_fig, height_fig, str_img)
> >
> >
> > val = report_memory(i)
> > # wait a few cycles for memory usage to stabilize
> > if i==indStart: start = val
> >
> > end = val
> > print 'Average memory consumed per loop: %1.4fk bytes' % \
> > ((end-start)/float(indEnd-indStart))
> >
> >
> >
> >
> > Here is the O/P
> >
> > $python memory_leak_map.py
> > rss vsz %mem
> > 0 47272 50632 9.7
> > 1 74412 77700 15.3
> > 2 93960 97380 19.3
> > 3 113308 116776 23.3
> > 4 132824 136416 27.3
> > 5 152352 155828 31.3
> > 6 171860 175216 35.3
> > 7 191372 194868 39.3
> > 8 210872 214248 43.3
> > 9 230336 233916 47.3
> > 10 249732 253284 51.3
> > 11 269252 272692 55.3
> > 12 288680 292336 59.3
> > 13 308108 311724 63.2
> > 14 305160 331112 62.6
> > 15 301096 350764 61.8
> > 16 304884 370160 62.6
> > 17 298276 389804 61.2
> > 18 305876 409184 62.8
> > 19 298316 428596 61.2
> > 20 307856 448224 63.2
> > 21 308004 467640 63.2
> > 22 308844 487016 63.4
> > 23 306260 506656 62.9
> > 24 300612 526052 61.7
> > Traceback (most recent call last):
> > File "memory_leak_map.py", line 41, in ?
> > area_thresh=1000.)
> > File
> >
> "/usr/local/lib/python2.4/site-packages/matplotlib/toolkits/basemap/basemap.py",
>
> > line 815, in __init__
> > self.riversegs = segments+segments2+segments3
> > MemoryError
> > Killed: 9
> >
> >
> > Can someone please help me out solving this problem?
> >
> >
> > Thanks
> > -Aalok
> >
> Aaolk: All your plots use the same map projection, yet you are
> initializing a new Basemap instance every time through the loop. Try
> moving the line
>
> map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
> area_thresh=1000.)
>
> outside the loop.
>
> -Jeff
>

Aaolk: Here's what I get with matplotlib 0.87.7, basemap 0.9.4, numpy
1.0 on MacOS 10.4.9 with python 2.5 (python 2.4 gives the same result):

[mac28:~/matplotlib/toolkits/basemap] jsw% python memleak.py
rss vsz %mem
0 28248 153200 -1.3
1 34028 157316 -1.6
2 34908 158084 -1.7
3 35688 158852 -1.7
4 36200 159364 -1.7
5 36712 159876 -1.8
6 36456 159620 -1.7
7 36712 159876 -1.8
8 36712 159876 -1.8
9 36712 159876 -1.8
10 36712 159876 -1.8
11 36712 159876 -1.8
12 36456 159620 -1.7
13 36712 159876 -1.8
14 36712 159876 -1.8
15 36712 159876 -1.8
16 36712 159876 -1.8
17 36712 159876 -1.8
18 36712 159876 -1.8
19 36712 159876 -1.8
20 36712 159876 -1.8
21 36712 159876 -1.8


The %mem flag doesn't appear to work right on MacOS X, but otherwise it
looks fine - no memory leak. I see you are using a pre-release version
of numpy - I wonder if that could be the problem?

-Jeff



--
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
325 Broadway Boulder, CO, USA 80305-3328

+qA@public.gmane.org>

Find out what India is talking about on - Yahoo! Answers India
Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Aalok kapoor | 1 Dec 15:16
Picon
Favicon

Re: Memory leaks in Basemap

After using numpy-1.0 the results are more bad. After 15 maps it is reaching to 71% memory usage. I am working on freeBSD box.

python memory_leak_map.py
     rss   vsz    %mem
0    47940 50636  9.8
1    75080 77700 15.4
2    94636 97380 19.4
3    114156 116776 23.4
4    133672 136416 27.4
5    153204 155832 31.4
6    172708 175216 35.5
7    192224 194872 39.5
8    211720 214248 43.5
9    231244 233916 47.5
10    250732 253280 51.5
11    270252 272688 55.5
12    289756 292332 59.5
13    309272 311728 63.5
14    328764 331108 67.5
15    347804 350760 71.4



thanks,
-Aalok
Aalok kapoor <aalok_kapoor1984-/E1597aS9LQxFYw1CcD5bw@public.gmane.org> wrote:

Hi,

Thanks for this direction. I am using Numpy-1.1. Do I not supposed to use this version? I will try to use older version and see what happens. I hope this will solve the problem.

thanks
-Aalok

Jeff Whitaker <jswhit <at> fastmail.fm> wrote:
Aalok kapoor wrote:
> Thanks for reply,
>
> This was just an example for mem leak in my application. Actually i
> want maps with different data to be loaded each time and the map
> objects taken once changees after ploting so i have to take different
> object each time. After around 20 maps generation it gives memory
> error to me.
>
> thanks,
> -Aalok
>
> */Jeff Whitaker /* wrote:
>
> Aalok kapoor wrote:
> > Hi all,
> >
> > I am using matplotlib-0.87.7, Basemap-0.9.3, Numpy-1.1 and agg
> backend.
> > I am facing memory leak problems after running following script -
> >
> >
> > import os, sys, time
> > import cStringIO
> > import Image
> > import matplotlib
> > matplotlib.use('Agg')
> >
> > import matplotlib.pylab as p
> > import matplotlib.numerix as nx
> > from matplotlib.toolkits.basemap import Basemap
> >
> > def get_image_bytes(width_fig, height_fig, str_img):
> > """Returns the bytes representing the image generated
> >
> > The createImage method should be called before calling this method.
> >
> > :Returns:
> > Byte data.
> > """
> > # Get the actual image data
> > f = cStringIO.StringIO()
> > dims = (width_fig, height_fig)
> > im = Image.fromstring("RGB", dims, str_img)
> > im.save(f, "JPEG")
> > return f.getvalue()
> >
> > def report_memory(i):
> > pid = os.getpid()
> > a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
> > print i, ' ', a2[1],
> > return int(a2[1].split()[1])
> >
> >
> >
> > # take a memory snapshot on indStart and compare it with indEnd
> > indStart, indEnd = 30, 150
> > print ' rss vsz %mem'
> > for i in range(indEnd):
> > p.figure(figsize=(float(640)/80.0,float(480)/80.0),
> > facecolor='w', edgecolor='w')
> > p.axes([0.0, 0.0, 1.0, 1.0])
> > map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
> > area_thresh=1000.)
> > # draw coastlines, country boundaries, fill continents.
> > map1.drawcoastlines(linewidth=.5)
> > map1.drawcountries()
> > map1.fillcontinents(color="#CEFFCE")
> > # draw the edge of the map projection region (the projection limb)
> > map1.drawmapboundary()
> > # compute the native map projection coordinates for cities.
> > lats, lons = ([18.728], [20.890])
> > x,y = map1(lons,lats)
> > # plot filled circles at the locations of the cities.
> > map1.plot(x,y,'bo')
> > canvas = p.get_current_fig_manager().canvas
> > agg = canvas.switch_backends \
> > (matplotlib.backends.backend_agg.FigureCanvasAgg)
> > agg.draw() # Takes ~.9 seconds
> > # get the image data
> > str_img = agg.tostring_rgb()
> > width_fig, height_fig = map(int, agg.figure.bbox.get_bounds()[2:])
> > p.cla()
> > p.close()
> > bytes = get_image_bytes(width_fig, height_fig, str_img)
> >
> >
> > val = report_memory(i)
> > # wait a few cycles for memory usage to stabilize
> > if i==indStart: start = val
> >
> > end = val
> > print 'Average memory consumed per loop: %1.4fk bytes' % \
> > ((end-start)/float(indEnd-indStart))
> >
> >
> >
> >
> > Here is the O/P
> >
> > $python memory_leak_map.py
> > rss vsz %mem
> > 0 47272 50632 9.7
> > 1 74412 77700 15.3
> > 2 93960 97380 19.3
> > 3 113308 116776 23.3
> > 4 132824 136416 27.3
> > 5 152352 155828 31.3
> > 6 171860 175216 35.3
> > 7 191372 194868 39.3
> > 8 210872 214248 43.3
> > 9 230336 233916 47.3
> > 10 249732 253284 51.3
> > 11 269252 272692 55.3
> > 12 288680 292336 59.3
> > 13 308108 311724 63.2
> > 14 305160 331112 62.6
> > 15 301096 350764 61.8
> > 16 304884 370160 62.6
> > 17 298276 389804 61.2
> > 18 305876 409184 62.8
> > 19 298316 428596 61.2
> > 20 307856 448224 63.2
> > 21 308004 467640 63.2
> > 22 308844 487016 63.4
> > 23 306260 506656 62.9
> > 24 300612 526052 61.7
> > Traceback (most recent call last):
> > File "memory_leak_map.py", line 41, in ?
> > area_thresh=1000.)
> > File
> >
> "/usr/local/lib/python2.4/site-packages/matplotlib/toolkits/basemap/basemap.py",
>
> > line 815, in __init__
> > self.riversegs = segments+segments2+segments3
> > MemoryError
> > Killed: 9
> >
> >
> > Can someone please help me out solving this problem?
> >
> >
> > Thanks
> > -Aalok
> >
> Aaolk: All your plots use the same map projection, yet you are
> initializing a new Basemap instance every time through the loop. Try
> moving the line
>
> map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
> area_thresh=1000.)
>
> outside the loop.
>
> -Jeff
>

Aaolk: Here's what I get with matplotlib 0.87.7, basemap 0.9.4, numpy
1.0 on MacOS 10.4.9 with python 2.5 (python 2.4 gives the same result):

[mac28:~/matplotlib/toolkits/basemap] jsw% python memleak.py
rss vsz %mem
0 28248 153200 -1.3
1 34028 157316 -1.6
2 34908 158084 -1.7
3 35688 158852 -1.7
4 36200 159364 -1.7
5 36712 159876 -1.8
6 36456 159620 -1.7
7 36712 159876 -1.8
8 36712 159876 -1.8
9 36712 159876 -1.8
10 36712 159876 -1.8
11 36712 159876 -1.8
12 36456 159620 -1.7
13 36712 159876 -1.8
14 36712 159876 -1.8
15 36712 159876 -1.8
16 36712 159876 -1.8
17 36712 159876 -1.8
18 36712 159876 -1.8
19 36712 159876 -1.8
20 36712 159876 -1.8
21 36712 159876 -1.8


The %mem flag doesn't appear to work right on MacOS X, but otherwise it
looks fine - no memory leak. I see you are using a pre-release version
of numpy - I wonder if that could be the problem?

-Jeff



--
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
325 Broadway Boulder, CO, USA 80305-3328

+qA@public.gmane.org>

Find out what India is talking about on - Yahoo! Answers India
Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Find out what India is talking about on - Yahoo! Answers India
Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Curt Bridges | 1 Dec 15:50
Picon
Favicon

Re: Memory leaks in Basemap

Jeff and Aalok,
I am in central MO and it doesn't bother me but, for some unknown reason I'm recieving correspondense between you two. You might want to start a new email instead of replying  to each other.  Have a nice day. Curt Bridges  

Aalok kapoor <aalok_kapoor1984-/E1597aS9LQxFYw1CcD5bw@public.gmane.org> wrote:
After using numpy-1.0 the results are more bad. After 15 maps it is reaching to 71% memory usage. I am working on freeBSD box.

python memory_leak_map.py
     rss   vsz    %mem
0    47940 50636  9.8
1    75080 77700 15.4
2    94636 97380 19.4
3    114156 116776 23.4
4    133672 136416 27.4
5    153204 155832 31.4
6    172708 175216 35.5
7    192224 194872 39.5
8    211720 214248 43.5
9    231244 233916 47.5
10    250732 253280 51.5
11    270252 272688 55.5
12    289756 292332 59.5
13    309272 311728 63.5
14    328764 331108 67.5
15    347804 350760 71.4



thanks,
-Aalok
Aalok kapoor <aalok_kapoor1984-/E1597aS9LQxFYw1CcD5bw@public.gmane.org> wrote:
Hi,

Thanks for this direction. I am using Numpy-1.1. Do I not supposed to use this version? I will try to use older version and see what happens. I hope this will solve the problem.

thanks
-Aalok

Jeff Whitaker <jswhit-97jfqw80gc6171pxa8y+qA@public.gmane.org> wrote:
Aalok kapoor wrote:
> Thanks for reply,
>
> This was just an example for mem leak in my application. Actually i
> want maps with different data to be loaded each time and the map
> objects taken once changees after ploting so i have to take different
> object each time. After around 20 maps generation it gives memory
> error to me.
>
> thanks,
> -Aalok
>
> */Jeff Whitaker /* wrote:
>
> Aalok kapoor wrote:
> > Hi all,
> >
> > I am using matplotlib-0.87.7, Basemap-0.9.3, Numpy-1.1 and agg
> backend.
> > I am facing memory leak problems after running following script -
> >
> >
> > import os, sys, time
> > import cStringIO
> > import Image
> > import matplotlib
> > matplotlib.use('Agg')
> >
> > import matplotlib.pylab as p
> > import matplotlib.numerix as nx
> > from matplotlib.toolkits.basemap import Basemap
> >
> > def get_image_bytes(width_fig, height_fig, str_img):
> > """Returns the bytes representing the image generated
> >
> > The createImage method should be called before calling this method.
> >
> > :Returns:
> > Byte data.
> > """
> > # Get the actual image data
> > f = cStringIO.StringIO()
> > dims = (width_fig, height_fig)
> > im = Image.fromstring("RGB", dims, str_img)
> > im.save(f, "JPEG")
> > return f.getvalue()
> >
> > def report_memory(i):
> > pid = os.getpid()
> > a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
> > print i, ' ', a2[1],
> > return int(a2[1].split()[1])
> >
> >
> >
> > # take a memory snapshot on indStart and compare it with indEnd
> > indStart, indEnd = 30, 150
> > print ' rss vsz %mem'
> > for i in range(indEnd):
> > p.figure(figsize=(float(640)/80.0,float(480)/80.0),
> > facecolor='w', edgecolor='w')
> > p.axes([0.0, 0.0, 1.0, 1.0])
> > map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
> > area_thresh=1000.)
> > # draw coastlines, country boundaries, fill continents.
> > map1.drawcoastlines(linewidth=.5)
> > map1.drawcountries()
> > map1.fillcontinents(color="#CEFFCE")
> > # draw the edge of the map projection region (the projection limb)
> > map1.drawmapboundary()
> > # compute the native map projection coordinates for cities.
> > lats, lons = ([18.728], [20.890])
> > x,y = map1(lons,lats)
> > # plot filled circles at the locations of the cities.
> > map1.plot(x,y,'bo')
> > canvas = p.get_current_fig_manager().canvas
> > agg = canvas.switch_backends \
> > (matplotlib.backends.backend_agg.FigureCanvasAgg)
> > agg.draw() # Takes ~.9 seconds
> > # get the image data
> > str_img = agg.tostring_rgb()
> > width_fig, height_fig = map(int, agg.figure.bbox.get_bounds()[2:])
> > p.cla()
> > p.close()
> > bytes = get_image_bytes(width_fig, height_fig, str_img)
> >
> >
> > val = report_memory(i)
> > # wait a few cycles for memory usage to stabilize
> > if i==indStart: start = val
> >
> > end = val
> > print 'Average memory consumed per loop: %1.4fk bytes' % \
> > ((end-start)/float(indEnd-indStart))
> >
> >
> >
> >
> > Here is the O/P
> >
> > $python memory_leak_map.py
> > rss vsz %mem
> > 0 47272 50632 9.7
> > 1 74412 77700 15.3
> > 2 93960 97380 19.3
> > 3 113308 116776 23.3
> > 4 132824 136416 27.3
> > 5 152352 155828 31.3
> > 6 171860 175216 35.3
> > 7 191372 194868 39.3
> > 8 210872 214248 43.3
> > 9 230336 233916 47.3
> > 10 249732 253284 51.3
> > 11 269252 272692 55.3
> > 12 288680 292336 59.3
> > 13 308108 311724 63.2
> > 14 305160 331112 62.6
> > 15 301096 350764 61.8
> > 16 304884 370160 62.6
> > 17 298276 389804 61.2
> > 18 305876 409184 62.8
> > 19 298316 428596 61.2
> > 20 307856 448224 63.2
> > 21 308004 467640 63.2
> > 22 308844 487016 63.4
> > 23 306260 506656 62.9
> > 24 300612 526052 61.7
> > Traceback (most recent call last):
> > File "memory_leak_map.py", line 41, in ?
> > area_thresh=1000.)
> > File
> >
> "/usr/local/lib/python2.4/site-packages/matplotlib/toolkits/basemap/basemap.py",
>
> > line 815, in __init__
> > self.riversegs = segments+segments2+segments3
> > MemoryError
> > Killed: 9
> >
> >
> > Can someone please help me out solving this problem?
> >
> >
> > Thanks
> > -Aalok
> >
> Aaolk: All your plots use the same map projection, yet you are
> initializing a new Basemap instance every time through the loop. Try
> moving the line
>
> map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
> area_thresh=1000.)
>
> outside the loop.
>
> -Jeff
>

Aaolk: Here's what I get with matplotlib 0.87.7, basemap 0.9.4, numpy
1.0 on MacOS 10.4.9 with python 2.5 (python 2.4 gives the same result):

[mac28:~/matplotlib/toolkits/basemap] jsw% python memleak.py
rss vsz %mem
0 28248 153200 -1.3
1 34028 157316 -1.6
2 34908 158084 -1.7
3 35688 158852 -1.7
4 36200 159364 -1.7
5 36712 159876 -1.8
6 36456 159620 -1.7
7 36712 159876 -1.8
8 36712 159876 -1.8
9 36712 159876 -1.8
10 36712 159876 -1.8
11 36712 159876 -1.8
12 36456 159620 -1.7
13 36712 159876 -1.8
14 36712 159876 -1.8
15 36712 159876 -1.8
16 36712 159876 -1.8
17 36712 159876 -1.8
18 36712 159876 -1.8
19 36712 159876 -1.8
20 36712 159876 -1.8
21 36712 159876 -1.8


The %mem flag doesn't appear to work right on MacOS X, but otherwise it
looks fine - no memory leak. I see you are using a pre-release version
of numpy - I wonder if that could be the problem?

-Jeff



--
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
325 Broadway Boulder, CO, USA 80305-3328

+7aSoNqFMcnyzNGBkw@public.gmane.org>

Find out what India is talking about on - Yahoo! Answers India
Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Find out what India is talking about on - Yahoo! Answers India
Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Want to start your own business? Learn how on Yahoo! Small Business.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Jeff Whitaker | 1 Dec 17:11
Favicon

Re: Memory leaks in Basemap

Aalok kapoor wrote:
> After using numpy-1.0 the results are more bad. After 15 maps it is 
> reaching to 71% memory usage. I am working on freeBSD box.
>
> python memory_leak_map.py
>      rss   vsz    %mem
> 0    47940 50636  9.8
> 1    75080 77700 15.4
> 2    94636 97380 19.4
> 3    114156 116776 23.4
> 4    133672 136416 27.4
> 5    153204 155832 31.4
> 6    172708 175216 35.5
> 7    192224 194872 39.5
> 8    211720 214248 43.5
> 9    231244 233916 47.5
> 10    250732 253280 51.5
> 11    270252 272688 55.5
> 12    289756 292332 59.5
> 13    309272 311728 63.5
> 14    328764 331108 67.5
> 15    347804 350760 71.4
>
>
>
> thanks,
> -Aalok
> */Aalok kapoor <aalok_kapoor1984@...>/* wrote:
>
>     Hi,
>
>     Thanks for this direction. I am using Numpy-1.1. Do I not supposed
>     to use this version? I will try to use older version and see what
>     happens. I hope this will solve the problem.
>
>     thanks
>     -Aalok
>
>     */Jeff Whitaker <jswhit@...>/* wrote:
>
>         Aalok kapoor wrote:
>         > Thanks for reply,
>         >
>         > This was just an example for mem leak in my application.
>         Actually i
>         > want maps with different data to be loaded each time and the
>         map
>         > objects taken once changees after ploting so i have to take
>         different
>         > object each time. After around 20 maps generation it gives
>         memory
>         > error to me.
>         >
>         > thanks,
>         > -Aalok
>         >
>         > */Jeff Whitaker /* wrote:
>         >
>         > Aalok kapoor wrote:
>         > > Hi all,
>         > >
>         > > I am using matplotlib-0.87.7, Basemap-0.9.3, Numpy-1.1 and agg
>         > backend.
>         > > I am facing memory leak problems after running following
>         script -
>         > >
>         > >
>         > > import os, sys, time
>         > > import cStringIO
>         > > import Image
>         > > import matplotlib
>         > > matplotlib.use('Agg')
>         > >
>         > > import matplotlib.pylab as p
>         > > import matplotlib.numerix as nx
>         > > from matplotlib.toolkits.basemap import Basemap
>         > >
>         > > def get_image_bytes(width_fig, height_fig, str_img):
>         > > """Returns the bytes representing the image generated
>         > >
>         > > The createImage method should be called before calling
>         this method.
>         > >
>         > > :Returns:
>         > > Byte data.
>         > > """
>         > > # Get the actual image data
>         > > f = cStringIO.StringIO()
>         > > dims = (width_fig, height_fig)
>         > > im = Image.fromstring("RGB", dims, str_img)
>         > > im.save(f, "JPEG")
>         > > return f.getvalue()
>         > >
>         > > def report_memory(i):
>         > > pid = os.getpid()
>         > > a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
>         > > print i, ' ', a2[1],
>         > > return int(a2[1].split()[1])
>         > >
>         > >
>         > >
>         > > # take a memory snapshot on indStart and compare it with
>         indEnd
>         > > indStart, indEnd = 30, 150
>         > > print ' rss vsz %mem'
>         > > for i in range(indEnd):
>         > > p.figure(figsize=(float(640)/80.0,float(480)/80.0),
>         > > facecolor='w', edgecolor='w')
>         > > p.axes([0.0, 0.0, 1.0, 1.0])
>         > > map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
>         > > area_thresh=1000.)
>         > > # draw coastlines, country boundaries, fill continents.
>         > > map1.drawcoastlines(linewidth=.5)
>         > > map1.drawcountries()
>         > > map1.fillcontinents(color="#CEFFCE")
>         > > # draw the edge of the map projection region (the
>         projection limb)
>         > > map1.drawmapboundary()
>         > > # compute the native map projection coordinates for cities.
>         > > lats, lons = ([18.728], [20.890])
>         > > x,y = map1(lons,lats)
>         > > # plot filled circles at the locations of the cities.
>         > > map1.plot(x,y,'bo')
>         > > canvas = p.get_current_fig_manager().canvas
>         > > agg = canvas.switch_backends \
>         > > (matplotlib.backends.backend_agg.FigureCanvasAgg)
>         > > agg.draw() # Takes ~.9 seconds
>         > > # get the image data
>         > > str_img = agg.tostring_rgb()
>         > > width_fig, height_fig = map(int,
>         agg.figure.bbox.get_bounds()[2:])
>         > > p.cla()
>         > > p.close()
>         > > bytes = get_image_bytes(width_fig, height_fig, str_img)
>         > >
>         > >
>         > > val = report_memory(i)
>         > > # wait a few cycles for memory usage to stabilize
>         > > if i==indStart: start = val
>         > >
>         > > end = val
>         > > print 'Average memory consumed per loop: %1.4fk bytes' % \
>         > > ((end-start)/float(indEnd-indStart))
>         > >
>         > >
>         > >
>         > >
>         > > Here is the O/P
>         > >
>         > > $python memory_leak_map.py
>         > > rss vsz %mem
>         > > 0 47272 50632 9.7
>         > > 1 74412 77700 15.3
>         > > 2 93960 97380 19.3
>         > > 3 113308 116776 23.3
>         > > 4 132824 136416 27.3
>         > > 5 152352 155828 31.3
>         > > 6 171860 175216 35.3
>         > > 7 191372 194868 39.3
>         > > 8 210872 214248 43.3
>         > > 9 230336 233916 47.3
>         > > 10 249732 253284 51.3
>         > > 11 269252 272692 55.3
>         > > 12 288680 292336 59.3
>         > > 13 308108 311724 63.2
>         > > 14 305160 331112 62.6
>         > > 15 301096 350764 61.8
>         > > 16 304884 370160 62.6
>         > > 17 298276 389804 61.2
>         > > 18 305876 409184 62.8
>         > > 19 298316 428596 61.2
>         > > 20 307856 448224 63.2
>         > > 21 308004 467640 63.2
>         > > 22 308844 487016 63.4
>         > > 23 306260 506656 62.9
>         > > 24 300612 526052 61.7
>         > > Traceback (most recent call last):
>         > > File "memory_leak_map.py", line 41, in ?
>         > > area_thresh=1000.)
>         > > File
>         > >
>         >
>         "/usr/local/lib/python2.4/site-packages/matplotlib/toolkits/basemap/basemap.py",
>         >
>         > > line 815, in __init__
>         > > self.riversegs = segments+segments2+segments3
>         > > MemoryError
>         > > Killed: 9
>         > >
>         > >
>         > > Can someone please help me out solving this problem?
>         > >
>         > >
>         > > Thanks
>         > > -Aalok
>         > >
>         > Aaolk: All your plots use the same map projection, yet you are
>         > initializing a new Basemap instance every time through the
>         loop. Try
>         > moving the line
>         >
>         > map1 = Basemap(projection='cyl', lat_0=50, lon_0=-100,
>         > area_thresh=1000.)
>         >
>         > outside the loop.
>         >
>         > -Jeff
>         >
>
>         Aaolk: Here's what I get with matplotlib 0.87.7, basemap
>         0.9.4, numpy
>         1.0 on MacOS 10.4.9 with python 2.5 (python 2.4 gives the same
>         result):
>
>         [mac28:~/matplotlib/toolkits/basemap] jsw% python memleak.py
>         rss vsz %mem
>         0 28248 153200 -1.3
>         1 34028 157316 -1.6
>         2 34908 158084 -1.7
>         3 35688 158852 -1.7
>         4 36200 159364 -1.7
>         5 36712 159876 -1.8
>         6 36456 159620 -1.7
>         7 36712 159876 -1.8
>         8 36712 159876 -1.8
>         9 36712 159876 -1.8
>         10 36712 159876 -1.8
>         11 36712 159876 -1.8
>         12 36456 159620 -1.7
>         13 36712 159876 -1.8
>         14 36712 159876 -1.8
>         15 36712 159876 -1.8
>         16 36712 159876 -1.8
>         17 36712 159876 -1.8
>         18 36712 159876 -1.8
>         19 36712 159876 -1.8
>         20 36712 159876 -1.8
>         21 36712 159876 -1.8
>
>
>         The %mem flag doesn't appear to work right on MacOS X, but
>         otherwise it
>         looks fine - no memory leak. I see you are using a pre-release
>         version
>         of numpy - I wonder if that could be the problem?
>
>         -Jeff
>
>
>
>         -- 
>         Jeffrey S. Whitaker Phone : (303)497-6313
>         NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
>         325 Broadway Boulder, CO, USA 80305-3328
>

Aaolk:  Since I can't reproduce your problem, I'm afraid I can't give 
you any concrete advice.  It could be Basemap, matplotlib, numpy, PIL or 
even python itself.  To narrow down the possibilities, you can try 
moving trimming your loop line by line and see if you can make it go 
away.  The python garbage collector interface 
(http://www.python.org/doc/2.4/lib/module-gc.html) might be of some help 
also.

-Jeff

--

-- 
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : Jeffrey.S.Whitaker@...
325 Broadway                Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Eric Firing | 3 Dec 04:21
Favicon
Gravatar

defaults and matplotlibrc

Norbert,

Your change in commenting out almost everything in matplotlibrc was a 
good one, but I think it had an unintended consequence: it changed the 
way everything looks because the defaults in __init__.py were not the 
same as the ones in matplotlibrc.  To my eye and on my machine the 
matplotlibrc defaults are better, and my guess is that this is because 
over a period of time people tuned the matplotlibrc values but left the 
__init__.py values alone--after all, they were normally not used.  In 
any case, I went ahead and changed __init__.py to match matplotlibrc.

Eric

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Eric Firing | 3 Dec 23:02
Favicon
Gravatar

Re: pcolor & colorbar with log normalised colour scale

Jim,

I have modified your LogNorm, added it to colors.py, made some changes 
to colorbar.py, and added a stripped-down version of your pcolor_log.py 
to the examples directory.  If you update your mpl from svn, then I 
think you will find that pcolor_log now works the way you expected it to 
originally, with the colorbar automatically supporting the log color scale.

Eric

JIM MacDonald wrote:
> Hi Eric,
> 
> Thanks for your reply. It made me realise a few things....
>> > But when I add a colorbar it goes wrong. The colorbar is labelled with
>> > the log of the values, rather
>> > than values, and the colour only fills the top third of the colorbar.
>>
>> In the absence of additional kwargs, colorbar uses norm.vmin and
>> norm.vmax to determine the limits of the colorbar, and it uses a default
>> formatter.  It has no way of knowing that you have taken the log of your
>> original values.
> Yes of course there is in inconsistency in my LogNorm class. norm.vmax
> will return the log of the maximum, when logically it should return
> the max of the actual maximum. I've modified my example to take this
> into account. see attached (and updated version online).
> 
> 
>> Colorbar will need some kwargs, at the very least.  The "format" kwarg,
>> for example, can be used to pass in a Formatter instance so that a label
>> is 10^-3 instead of -3.
> Ah I'd not discovered Formatters yet. But this does give a good solution.
> If I instead do a pcolor of the log of my data, and then use a
> FormatStrFormatter as you surgested:
> 
> pcolor(X,Y,log10(Z1),shading='flat')
> colorbar(format=FormatStrFormatter('$10^{%d}$'))
> 
> I get exactly what I want :-) Its not the most intuitive way to do it,
> but it works and I can't see any major drawbacks.
> 
>> I am not sure why only the top is colored in your example--it might be a
>> bug or it might be an indication that additional kwargs are needed.  I
>> am reasonably sure there is a simple solution, but I can't look at it
>> any more right now--maybe I can get back to it this evening.
> 
> I'm pretty sure the reason only the top was coloured is to do in the
> inconsistency I described above. Once I fixed that the colorbar is
> fine except that it is not on a log scale. But of course it can't know
> that it is suppost to be on a log scale! I tried to do:
> 
> gca().axes[1].set_ylim((1e-5,1))
> gca().axes[1].set_yscale('log')
> 
> but that doesn't work. I get a load of errors :
> 
> exceptions.ValueError                                Traceback (most
> recent call last)
> 
> /usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py in
> expose_event(self, widget, event)
>    282                 x, y, w, h = self.allocation
>    283                 self._pixmap_prepare (w, h)
> --> 284                 self._render_figure(self._pixmap, w, h)
>    285                 self._need_redraw = False
>    286
> 
> /usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtkagg.py
> in _render_figure(self, pixmap, width, height)
>     71     def _render_figure(self, pixmap, width, height):
>     72         if DEBUG: print 'FigureCanvasGTKAgg.render_figure'
> ---> 73         FigureCanvasAgg.draw(self)
>     74         if DEBUG: print 'FigureCanvasGTKAgg.render_figure
> pixmap', pixmap
>     75         #agg_to_gtk_drawable(pixmap, self.renderer._renderer, None)
> 
> /usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py in
> draw(self)
>    390
>    391         renderer = self.get_renderer()
> --> 392         self.figure.draw(renderer)
>    393
>    394     def get_renderer(self):
> 
> /usr/lib/python2.4/site-packages/matplotlib/figure.py in draw(self, 
> renderer)
>    542
>    543         # render the axes
> --> 544         for a in self.axes: a.draw(renderer)
>    545
>    546         # render the figure text
> 
> /usr/lib/python2.4/site-packages/matplotlib/axes.py in draw(self,
> renderer, inframe)
>   1061
>   1062         for zorder, i, a in dsu:
> -> 1063             a.draw(renderer)
>   1064
>   1065         self.transData.thaw()  # release the lazy objects
> 
> /usr/lib/python2.4/site-packages/matplotlib/patches.py in draw(self, 
> renderer)
>    163
>    164         verts = self.get_verts()
> --> 165         tverts = self._transform.seq_xy_tups(verts)
>    166
>    167         renderer.draw_polygon(gc, rgbFace, tverts)
> 
> ValueError: Domain error on nonlinear Transformation::seq_xy_tups
> operator()(thisx, thisy)
> 
> As for how to solve the problem properly. Matlab allows one to set to
> caxis scale to log. Maybe colorbar could detect that the norm instance
> was an instance of LogNorm and scale the yaxis logarithmicly. Or would
> it be better to put a scale={'log','linear'} kwarg into colorbar()?
> 
> Thanks again for your help.
> 
> cheers
> 
> JIM
> ---

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Eric Firing | 4 Dec 07:57
Favicon
Gravatar

"consume the generator"?

Despite the comment, I don't understand the purpose of the last line in 
the following excerpt from the Axes.plot() method:

         lines = []
         for line in self._get_lines(*args, **kwargs):
             self.add_line(line)
             lines.append(line)
         lines = [line for line in lines] # consume the generator

Would someone enlighten me, please?  Or is that line in fact as useless 
as it appears to me?

Thanks.

Eric

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Leandro Lameiro | 4 Dec 12:32
Picon

Re: Qt backend submit

Hello James

Essentially the qt event-loop will only be started by matplotlib if matplotlib was the one to create the qApp, if not then it is up
to the creator of the Qt qApp to start the event-loop when they are ready for it.  This allows for applications with embedded Qt
event loops to work with matplotlib.  I have run some test cases in a few different python environments (including the vanilla
python) and all seem to be working.  I have not, however tested this in the iPython environment (although I don't think that iPython
uses Qt, does it?).

Yes, it does. There is a command-line switch to make iPython run the qt mainloop in a separate thread.

Use "ipython -qthread".

Also, there is "ipython -pylab" that run default GUI toolkit (as defined in matplotlibrc) mainloop in a thread.

--
Regards
Leandro Lameiro

Blog: http://lameiro.wordpress.com
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Gmane