SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S




1
(3)
2
(9)
3
(4)
4
(1)
5
6
(5)
7
(8)
8
(11)
9
(15)
10
(5)
11
(2)
12
13
(7)
14
(4)
15
(13)
16
(6)
17
(1)
18
19
(16)
20
(10)
21
(13)
22
(13)
23
(3)
24
(1)
25
(3)
26
(4)
27
(1)
28
(6)
29
(6)
30
(1)
31

Showing 4 results of 4

From: John H. <jdh...@ac...> - 2004年07月14日 14:37:39
>>>>> "Matthew" == Matthew O'Connnor <mat...@ca...> writes:
 Matthew> Hi, I was wondering if anybody else was seeing memory
 Matthew> leaks in the latest version (0.60.2).
 Matthew> I'm using the Agg backend to produce images for web
 Matthew> pages.
 Matthew> The release notes for 0.60.2 indicate that memory leaks
 Matthew> have been fixed. Are there any known leaks left?
Yes, when I say memory leaks were fixed, I mean I identified and fixed
some, but am not claiming that all are fixed. There are known memory
leaks. For example, there is a small leak in freetype2 that was fixed
in freetype CVS but may not be released yet. There appears to be a
leak in _backend_agg's write_png method, but I haven't traced this
sufficiently to find if it is in my code or in libpng or in zlib.
The whole memory leak situation has continued to improve as I've
migrated almost all of the extension code to pycxx, and I have a
number of unit tests to test leaks in various components. For
example, there are no detectable leaks in the transforms module.
Below is a prototypical script that I use to diagnose and report
memory leaks. Please use something like it when reporting leaks so I
get an idea of the magnitude of the problem (ie bytes per figure).
Also please provide your platform, matplotlib version, backend and as
much information about the versions of the libraries you are using:
freetype, png and zlib. It would also help if you posted code so I
could look for any obvious coding errors vis-a-vis matplotlib.
Running the code below, I'm getting about 400 bytes / per / figure
(matplotlib-0.60.2 / agg on linux with freetype 2.17, libpng1.2 and
libz 1.1.4). I know leaks of this size can cause troubles on an
application server, and in animated figures, and will continue to try
and track them down. As I noted above, some of this results from the
libraries on which matplotlib depends, and so may be system and
version dependent. If your numbers are much worse, it may be that you
are doing something wrong, ie, not properly closing, reusing figure,
etc.
Let me know what you find,
JDH
import os, sys, time
import matplotlib
matplotlib.use('Agg')
from matplotlib.matlab import *
def report_memory(i):
 pid = os.getpid()
 a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
 print i, ' ', a2[1],
 return int(a2[1].split()[1])
N = 100
for i in range(N):
 ind = arange(100)
 xx = rand(len(ind), 1)
 figure(1)
 plot(ind, xx[:,0])
 savefig('tmp%d.png' % i, dpi = 75)
 close(1)
 val = report_memory(i)
 if i==1: start = val
end = val
print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(N))
From: John H. <jdh...@ac...> - 2004年07月14日 14:23:18
>>>>> "Jeff" == Jeff Whitaker <js...@fa...> writes:
 Jeff> John: I found that if I just call proj with all the lats and
 Jeff> lons at once (instead of once for each segment) I can speed
 Jeff> it up tremendously. Here's what I tried, using the new
 Jeff> LineCollection snippets you sent me, and the updated
 Jeff> matplotlib snapshot:
Yep - very good idea. Your mistake with the line collection is how
you define the segments. From matplotlib.collections.LineCollection
documentation
 segments is a sequence of ( line0, line1, line2), where linen =
 (x0, y0), (x1, y1), ... (xm, ym). Each line can be a different
 length
That is, it is a sequence of sequences of xy tuples. When you write
zip(xs.tolist(),ys.tolist()), you have a sequence of xy tuples. If
you plotted this, you would have one giant, connected line, which is
not what you want. You want a series of disconnected lines. Thus you
need to keep track of the indices where each separate segment starts,
and split out the segments, as in the code below.
For future reference, you may also want to use PolyCollections if you
want to generate a map and you have a bunch of segments defined by
sequences of xy tuples with associated face colors. 
There was no significant difference between using bilinear
interpolation with antialiased drawing vs nearest neighbor
interpolation w/o aa, so I turned both back on.
And don't forget to try the new toolbar....
I noticed that the lat/lon lines don't precisely agree with the
colormap, eg around the Aleutian Islands the light blue is not
perfectly registered with the black lines. Should I be concerned that
this reflects a problem in matplotlib, or is this kind of error
standard in the data you've provided? I think this is related to the
pixel border that appears around some images, and is magnified when
interpolation is used because the top and right borders are not
defined when interpolating. I'll continue to look into this.
Would it be OK if I used this example on the web page? I like it!
Enjoy,
JDH
import cPickle
from matplotlib.matlab import *
from matplotlib.collections import LineCollection 
from proj import Proj
import Numeric
# standard parallels at 50 deg N, center longitued 107 deg W.
params = {}
params['proj'] = 'lcc'
params['R'] = 63712000
params['lat_1'] = 50
params['lat_2'] = 50
params['lon_0'] = -107
proj = Proj(params)
llcornerx, llcornery = proj(-145.5,1.)
params['x_0'] = -llcornerx # add cartesian offset so lower left corner = (0,0)
params['y_0'] = -llcornery
# create a Proj instance for desired map.
proj = Proj(params)
# set the default params for imshow
rc('image', origin='lower', cmap='jet')
ax = subplot(111)
nx = 349; ny = 277
dx = 32463.41; dy = 32463.41
xmax = (nx-1)*dx; ymax = (ny-1)*dy # size of domain to plot
C = cPickle.load( file('topodata.pickle','rb') )
im = ax.imshow(C, interpolation='bilinear',
 extent=(0, xmax, 0, ymax))
# ind is the index for the start of a new group
lons = []; lats = []; ind = []
i = 0 # the current ind
for line in file('wcl.txt'):
 if line.startswith('# -b'):
 ind.append(i)
 continue
 
 # lon/lat
 lon, lat = [float(val) for val in line.split('\t')]
 lons.append(lon)
 lats.append(lat)
 i += 1
xs, ys = proj(Numeric.array(lons),Numeric.array(lats))
#a sequence of xy tuples
segments = [zip(xs[i0:i1], ys[i0:i1]) for i0, i1 in zip(ind[:-1], ind[1:])]
collection = LineCollection(
 segments, 
 colors = ( (0,0,0,1), ), # black 
 linewidths = (1.5,), 
 antialiaseds = (1,),) # turn off aa for speed 
ax.add_collection(collection)
corners = (min(xs), min(ys)), (max(xs), max(ys))
ax.update_datalim( corners )
axis([0, xmax, 0, ymax])
ax.set_xticks([]) # no ticks
ax.set_yticks([])
title('Lambert Conformal Conic Projection') 
#savefig('test')
show() 
From: Jeff W. <js...@fa...> - 2004年07月14日 12:26:31
On 2004年7月13日, John Hunter wrote:
>
> OK, made some headway here.
>
....
>
> For the line part of the map, I extended the
> matplotlib.collections.LineCollection class to handle a sequence of
> lines, where each line is defined by a list of tuples (x0,y0), (x1,
> y1), ... Thus all of your lines are handled by a single object,
> rather than having 1800+ separate line objects created in plot.
> Again, no python loops required.
>
> In the current form, the code takes about 1.15s to run on my machine
> and is about 30x faster than the original code you posted which
> includes the data loading part. Nonetheless, the matplotlib part is
> much faster too, as you'll see when you interact with the data.
>
John: I found that if I just call proj with all the lats and lons at 
once (instead of once for each segment) I can speed it up tremendously. 
Here's what I tried, using the new LineCollection snippets you sent me, 
and the updated matplotlib snapshot:
from matplotlib.matlab import *
from matplotlib.collections import LineCollection 
from proj import Proj
import Numeric, time
# open file with coastline data (from world coastline database).
wcl = open('wcl.txt')
# set up map projection parameters (lambert conformal conic,
# standard parallels at 50 deg N, center longitued 107 deg W.
params = {}
params['proj'] = 'lcc'
params['R'] = 63712000
params['lat_1'] = 50
params['lat_2'] = 50
params['lon_0'] = -107
proj = Proj(params)
llcornerx, llcornery = proj(-145.5,1.)
params['x_0'] = -llcornerx # add cartesian offset so lower left corner = (0,0)
params['y_0'] = -llcornery
# create a Proj instance for desired map.
proj = Proj(params)
# set the default params for imshow 
rc('image', origin='lower', cmap='jet')
ax = subplot(111) 
nx = 349; ny = 277 
dx = 32463.41; dy = 32463.41 
xmax = (nx-1)*dx; ymax = (ny-1)*dy # size of domain to plot
t1 = time.clock()
segnum = 0
lons = []
lats = []
for line in wcl:
 splitline = line.split()
 if splitline[0] != '#':
 lon = float(splitline[0])
 	lat = float(splitline[1])
 	lons.append(lon)
 	lats.append(lat)
xs, ys = proj(Numeric.array(lons),Numeric.array(lats))
minx, maxx = min(xs), max(xs) 
miny, maxy = min(ys), max(ys) 
xypts = zip(xs.tolist(),ys.tolist())
wcl.close() # close coastline file
# all args are sequences, length 1 in case of linewidths and 
# antialiased 
collection = LineCollection(segments = xypts,
 colors = ( (0,0,0,1), ), # black
 linewidths = (1.5,),
 antialiaseds = (0,),) # turn off aa for speed 
ax.add_collection(collection) 
ax.update_datalim( ((minx, miny), (maxx, maxy)))
axis([0, xmax, 0, ymax]) 
ax.set_xticks([]) # no ticks 
ax.set_yticks([]) 
title('Lambert Conformal Conic Projection') 
t2 = time.clock()
print t2-t1
show()
But when I run it, I get the following error:
Traceback (most recent call last):
 File 
"/sw/lib/python2.3/site-packages/matplotlib/backends/backend_gtkagg.py", 
line 75, in callback
 self.draw()
 File 
"/sw/lib/python2.3/site-packages/matplotlib/backends/backend_gtkagg.py", 
line 42, in draw
 agg.draw()
 File 
"/sw/lib/python2.3/site-packages/matplotlib/backends/backend_agg.py", line 
291, in draw
 self.figure.draw(self.renderer)
 File "/sw/lib/python2.3/site-packages/matplotlib/figure.py", line 236, 
in draw
 for a in self.axes: a.draw(renderer)
 File "/sw/lib/python2.3/site-packages/matplotlib/axes.py", line 668, in 
draw
 c.draw(renderer)
 File "/sw/lib/python2.3/site-packages/matplotlib/collections.py", line 
286, in draw
 self._transOffset)
TypeError: CXX: type error.
-Jeff
 -- 
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/CDC1 FAX : (303)497-6449
325 Broadway Web : http://www.cdc.noaa.gov/~jsw
Boulder, CO, USA 80305-3328 Office: Skaggs Research Cntr 1D-124
From: Matthew O'C. <mat...@ca...> - 2004年07月14日 01:37:29
Hi,
I was wondering if anybody else was seeing memory leaks in the latest
version (0.60.2).
I'm using the Agg backend to produce images for web pages.
The release notes for 0.60.2 indicate that memory leaks have been fixed.
Are there any known leaks left?
Cheers,
Matthew O'Connor

Showing 4 results of 4

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /