matplotlib/pylab memory usage

matplotlib/pylab memory usage
Hi matplotlib users and developers,

I am trying to run a web application using matplotlib in a memory constrained environment. I have therefore tried to figure out what memory overhead matplotlib incurs. When I run the following method prior to and after importing pylab and matplotlib respectively I get:

def report_memory():

import os

pid = os.getpid()

a2 = os.popen(‘ps -p %d -o rss,vsz,%%mem’ % pid).readlines()

print a2[1],

return int(a2[1].split()[1])

import numpy

report_memory()

#import pylab

#import matplotlib

report_memory()

$ python test.py

5976 17872 0.5

15608 41924 1.5

$ python test.py

5972 17824 0.5

7608 20608 0.7

I am importing numpy separately since I need it for other purposes. So pylab uses ~24 MB while matplotlib uses 2.8 MB. Does this mean that I should rewrite my application so that it does not depend on pylab or will the matplotlib memory usage ramp up as I import sub modules? What is your experience?

Regards,

Jesper

I've never needed to ask this question, so I don't know the answer, but I would suspect pylab, in reality, adds very little overhead to matplotlib.

But -- I would modify your test script to actually perform a plot using pylab vs. matplotlib API. Until you actually "do" something, you're just measuring the cost of importing and initialization, which is likely not the significant part of memory usage.

Also, make sure you aren't using a GUI backend. Use Agg, Pdf, Svg, Ps etc. depending on your desired output. The GUI backends will not only take up more memory, but they can break inside of a CGI/mod_python environment where you don't have an X server.

Cheers,
Mike

Larsen, Jesper wrote:

···

Hi matplotlib users and developers,

I am trying to run a web application using matplotlib in a memory constrained environment. I have therefore tried to figure out what memory overhead matplotlib incurs. When I run the following method prior to and after importing pylab and matplotlib respectively I get:

def report_memory():
  import os
  pid = os.getpid()
  a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
  print a2[1],
  return int(a2[1].split()[1])

import numpy
report_memory()
#import pylab
#import matplotlib
report_memory()

python test\.py 5976 17872 0\.5 15608 41924 1\.5 python test.py
5972 17824 0.5
7608 20608 0.7

I am importing numpy separately since I need it for other purposes. So pylab uses ~24 MB while matplotlib uses 2.8 MB. Does this mean that I should rewrite my application so that it does not depend on pylab or will the matplotlib memory usage ramp up as I import sub modules? What is your experience?

Regards,
Jesper

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA