[Matplotlib-users] 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 - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Negative aspect ratios in basemap
Hi matplotlib-users, I have an application in which regions that are not known beforehand are defined and plotted. When the application plots a region a Basemap instance is created. My datasets define longitudes from 0 to 360. When regions cross the Greenwich meridian I try to make a Basemap like this: m = Basemap(350, -10, 10, 10) print m.aspect But this results in negative aspect ratios. How would you handle that? Will I have to make extra checks for whether the region crosses the 0 meridian and add 360 to all longitudes > 0 or do you have a better solution? (i.e. create m = Basemap(350, -10, 370, 10)) Regards, Jesper - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] matplotlib.toolkits.basemap. Basemap overlays?
Jim Vickroy wrote: >Thanks for the detailed explanation; I may be starting to understand the >significance of *figure*. >I was hoping to avoid repeated calls like map.drawcoastlines(), >map.drawcountries(), map.fillcontinents(color='0.95'), >map.drawmapboundary(), map.drawmeridians(plot.arange(0,360,30)), and >map.drawparallels(plot.arange(-90,90,30)). So, I will follow your >example and experiment to see what works and what does not to better >understand the behaviors. Hi Jim and others, You should definitely reuse the basemap instance but from your reply it seems like you would also like to reuse the figure instance. The current figure instance is changed when you make plot commands like map.drawcountries(). What I do is to remove the stuff that should not be reused. That is something like this: # If first time create figure from basemap using my function getfigure if fig == None: fig = getfigure(map) # The figure I am plotting on has two axes which I change - an axes with the plot and an axes with a colorbar ax = fig.get_axes()[0] cax = fig.get_axes()[1] # Create plot and save figure cs = map.contourf(lon, lat, data, ax=ax) fig.colorbar(cs, cax=cax, orientation='vertical', extend='both') fig.savefig(filename) # Remove contourf axes ContourSets for c in cs.collections: ax.collections.remove(c) # Remove colorbar axes ContourSets cax.collections = [] Hope it helps. Regards, Jesper <>- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] "plot" issue
Hi, When I try to plot a time series of numpy masked array data containing 2 values and with one of them masked out my machine chokes (memory usage of more than 900 mb for the script below). The culprit seem to be my use of use the matplotlib.dates.HourLocator on the x axis. Here is a small script illustrating the problem: --- import numpy as npy import pylab, matplotlib data = npy.ma.masked_values([0, 1], 0) dates = npy.array([731186.9167, 731187.0417]) #This does not help either #dates = npy.ma.array([731186.9167, 731187.0417], mask=data.mask) pylab.plot(dates, data) majloc = matplotlib.dates.HourLocator(interval=3) ax = pylab.gca() ax.xaxis.set_major_locator(majloc) pylab.savefig('test.png') --- System info: Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 >>> print matplotlib.__version__ 0.90.1 >>> print numpy.__version__ 1.0.3 Regards, Jesper - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] NetCDF input/output/plotting using Matplotlib w/ Basemap
Hi Zane, >This all seems to suggest to me, after a little poking around, that the >NetCDF file format would be good. I've managed to get SciPy and >Matplotlib and Basemap installed and apparently working together >happily... but I can't seem to find any "official" module within that >structure for writing NetCDF files. There are references to the old >Scientific.IO.NetCDF package, and I found something that had been >hanging around in the scipy.sandbox area... but which isn't there any >more. There's quite a list of Python interfaces to NetCDF on the >Unidata website... but they don't make any recommendations as to which >is "best". >If I'm going to be working within Matplotlib and Basemap and SciPy, does >anyone have a good recommendation for which NetCDF Python package to >use? Or issues I should consider? I have been very happy with PyNIO. The main reason I choose this package was that it has support for other formats as well (e.g. GRIB) and is actively developed and has great support. The next version of it will also be open source if that matters. Another package which I have been looking at is netcdf4-python. The interface seems very similar to that of PyNIO and it has some nice features that are not present in the PyNIO package. I really like the features that are handling Climate and Forecast convention specialities. These are date conversion utilities (which I am using in combination with the PyNIO package) and automatic packing and unpacking. Hope this helps, Jesper <>- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users