[Matplotlib-users] Memory leaks in a web application

2009-02-08 Thread A B
Hi,

Following is my post to the Django mailing list from yesterday. The response
was that Django isn't known to leak memory so there should be something off
with matplotlib or rather that way I am using it.
Hopefully someone here could comment on what could be causing the leaks.
Thanks in advance.




I am using matplotlib/pyplot on my site to dynamically generate PNG
plots. And I am experiencing dramatic memory leaks. Within 10-15
hits,  my Apache process grows from 15-20M to 100M.

I am using Django 1.0.2-final, Apache 2.2.1, Python 2.4.3, matplotlib
0.98.5.2. The leak happens under both Apache (with mod_wsgi 2.3) and
the development server. My OS is RHEL5.

Below is a simple code snippet that causes the leak. Please let me
know if I am doing something wrong or if there is a better way to
write this. Thanks.



from matplotlib import pyplot

def test_graph (request):

   f = pyplot.figure()
   ax = f.add_subplot(111)
   ax.plot([1,2,3])

   ax.fill_between([1,2,3],[1,2,3],[1.1,2.1,3.1])

   ax.grid(True)
   ax.legend(['hello'],
 'upper right', shadow=True, fancybox=True)
   ax.set_xlabel('Time')
   ax.set_ylabel('Value ')

   f.text(.5, 0.93, 'my title', horizontalalignment='center')

   response = HttpResponse(content_type='image/png')

### both ways causes a leak

   f.savefig( response, format = 'png' )
OR
   canvas = FigureCanvas(f)
   canvas.print_png(response)
   canvas = None

   ax = None
   f = None

   return response
--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leaks in a web application

2009-02-08 Thread Jouni K . Seppänen
A B  writes:

>f = pyplot.figure()

When you do this, matplotlib retains a reference to the figure until you
close it so that you can go back to it with e.g. figure(4). So add
pyplot.close(f) to your script. Or, even better, use the object-oriented
API. To get started with that, see

http://matplotlib.sourceforge.net/leftwich_tut.txt

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] controlling tick label size

2009-02-08 Thread Alan Jackson
Trying to find a simple way to shrink the tick labels for this plot -
since I can have many tiny histograms, the labels need to be smaller,
but it isn't obvious to me how to simply shrink them.

code snippet...

num = len(datasets)
fig = plt.figure()
rows = np.int(np.sqrt(num))
cols = np.int(float(num)/float(rows)+.9)
for i in range(num):
ax = fig.add_subplot(rows, cols, i+1)
ax.hist(datasets[i][np.isfinite(datasets[i])], bins=60 )
ax.set_xlabel(labels[i], size = 9)
ax.set_ylabel('Counts', size = 9)
plt.show()


-- 
---
| Alan K. Jackson| To see a World in a Grain of Sand  |
| [email protected]  | And a Heaven in a Wild Flower, |
| www.ajackson.org   | Hold Infinity in the palm of your hand |
| Houston, Texas | And Eternity in an hour. - Blake   |
---

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] controlling tick label size

2009-02-08 Thread Alan Jackson
Never mind - I just saw the very timely e-mail from Jouni.

Thanks!

On Sun, 8 Feb 2009 14:16:59 -0600
Alan Jackson  wrote:

> Trying to find a simple way to shrink the tick labels for this plot -
> since I can have many tiny histograms, the labels need to be smaller,
> but it isn't obvious to me how to simply shrink them.
> 
> code snippet...
> 
> num = len(datasets)
> fig = plt.figure()
> rows = np.int(np.sqrt(num))
> cols = np.int(float(num)/float(rows)+.9)
> for i in range(num):
> ax = fig.add_subplot(rows, cols, i+1)
> ax.hist(datasets[i][np.isfinite(datasets[i])], bins=60 )
> ax.set_xlabel(labels[i], size = 9)
> ax.set_ylabel('Counts', size = 9)
> plt.show()
> 
> 
> -- 
> ---
> | Alan K. Jackson| To see a World in a Grain of Sand  |
> | [email protected]  | And a Heaven in a Wild Flower, |
> | www.ajackson.org   | Hold Infinity in the palm of your hand |
> | Houston, Texas | And Eternity in an hour. - Blake   |
> ---
> 
> --
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


-- 
---
| Alan K. Jackson| To see a World in a Grain of Sand  |
| [email protected]  | And a Heaven in a Wild Flower, |
| www.ajackson.org   | Hold Infinity in the palm of your hand |
| Houston, Texas | And Eternity in an hour. - Blake   |
---

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] release candidate

2009-02-08 Thread John Hunter
We have accumulated a number of bug fixes in our stable release
branch, so I would like to release the 3rd bugfix release.  Please
test and report any problems

  
http://matplotlib.sourceforge.net/release-candidates/matplotlib-0.98.5.3.tar.gz

Charlie, will you have any time early next week for the windows
builds?  I can handle the OSX and src release.

Thanks,
JDH

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] different Locator for opposite axes

2009-02-08 Thread Thomas Robitaille
Hi everyone,

I am plotting a figure where I need two independent x axes and two  
independent y axes. I've tried to use both twinx and twiny at the  
same time, and this works to some extent, but it looks like it is  
plotting the labels for the bottom x axis and the right-hand y axis  
twice, which makes me think that I must be doing something wrong (the  
numbers appear more 'bold'). The code is below. Is there a better way  
to do this?

In reality, I don't need a different scale for the opposite axes, but  
I want to specify different Locator functions, but I assume that  
creating a new axes instance as done below is the only way to do this?

Thanks for any advice,

Thomas

###
fig = figure()
ax  = fig.add_subplot(111)
ax2 = ax.twinx().twiny()
for tick in ax.yaxis.get_major_ticks():
tick.label1On = True
tick.label2On = False
tick.tick1On = True
tick.tick2On = False
for tick in ax.xaxis.get_major_ticks():
tick.label1On = True
tick.label2On = False
tick.tick1On = True
tick.tick2On = False
for tick in ax2.yaxis.get_major_ticks():
tick.label1On = False
tick.label2On = True
tick.tick1On = False
tick.tick2On = True
for tick in ax2.xaxis.get_major_ticks():
tick.label1On = False
tick.label2On = True
tick.tick1On = False
tick.tick2On = True
ax.scatter([0.4],[0.6])
ax2.scatter([10.],[10.])
draw()
###


--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] release candidate

2009-02-08 Thread Charlie Moad
Sure.  Just send me a note when the src is ready.

- Charlie

On Sun, Feb 8, 2009 at 3:46 PM, John Hunter  wrote:
> We have accumulated a number of bug fixes in our stable release
> branch, so I would like to release the 3rd bugfix release.  Please
> test and report any problems
>
>  
> http://matplotlib.sourceforge.net/release-candidates/matplotlib-0.98.5.3.tar.gz
>
> Charlie, will you have any time early next week for the windows
> builds?  I can handle the OSX and src release.
>
> Thanks,
> JDH
>

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] rc params strangeness/error

2009-02-08 Thread Leo Trottier
Hi,

Did anyone have any insight on this?  Alternatively, anyone know why there
has been little uptake on this question ...(apologies that it was
accidentally sent twice)?

Leo

On Tue, Feb 3, 2009 at 11:42 PM, Leo Trottier  wrote:

> Matplotlib 0.98.5.2
> Location: C:\leo\.matplotlib
> Running Windows XP SP2
> Obtained from pythonxy v. 2.1.10
> No rc customizations ...
>
> I've been having a devil of a time getting my rcParams to update
> mid-script.  Perhaps this isn't possible, but if that's so, it's not
> entirely clear.  Even if it is so, this is seemingly a defect, because in an
> interactive session one expects quite different behavior (and no amount of
> iPython %reset-ing seems to be able to help).
>
> Note that manually setting the font (or what have you) in *title* works
> fine.
>
> Here is some example code:
>
> ## BEGIN #
> import matplotlib
> from matplotlib import rc, rcParams, rcdefaults
> from matplotlib.pyplot import plot, show, figure, title
>
> print matplotlib.__version__
> print matplotlib.get_configdir()
> print
> print "rcParams['font.sans-serif']:", rcParams['font.sans-serif']
> print 'family is:', rcParams['font.family']
> print
> figure(4)
> title('This should be in a sans-serif font')
> show()
>
> rcParams['font.sans-serif'] = rcParams['font.monospace']
> print "rcParams['font.sans-serif']:", rcParams['font.sans-serif']
> print 'family is:', rcParams['font.family']
> print
> figure(1)
> title('This should be in a monospace font')
> show()
>
> rcParams['font.sans-serif'] = rcParams['font.serif']
> print "rcParams['font.sans-serif']:", rcParams['font.sans-serif']
> print 'family is:', rcParams['font.family']
> print
> figure(2)
> title('This should be in a serif font')
> show()
>
> rcdefaults()
> print "rcParams['font.sans-serif']:", rcParams['font.sans-serif']
> print 'family is:', rcParams['font.family']
> print
> figure(3)
> title('This should be back to a sans-serif font')
> show()
> # END 
>
--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] different Locator for opposite axes

2009-02-08 Thread Jae-Joon Lee
Since you call twinx then twiny, you're creating two additional axes, not one.
And I guess this is why labels are drawn twice. You may do

def twin(ax):
ax2 = ax.figure.add_axes(ax.get_position(True),
   frameon=False)
ax2.yaxis.tick_right()
ax2.yaxis.set_label_position('right')
ax.yaxis.tick_left()

ax2.xaxis.tick_top()
ax2.xaxis.set_label_position('top')
ax.xaxis.tick_bottom()

return ax2

ax = gca()
ax2 = twin(ax)
ax.scatter([0.4],[0.6])
ax2.scatter([10.],[10.])

draw()


Note that you need to manually adjust the view limits of each axes. If
you use sharex or sharey parameters for the axes, you can share their
view limits (this is how axes is created when twinx and twiny is
called). But then you cannot have different tick locators.

In case you need an axes with a same viewlimit as the original one but
just want to place ticks at different position, you may check my
related post.

http://sourceforge.net/mailarchive/forum.php?thread_name=4985DED6.90108%40head.cfa.harvard.edu&forum_name=matplotlib-users

-JJ


On Sun, Feb 8, 2009 at 5:07 PM, Thomas Robitaille
 wrote:
> Hi everyone,
>
> I am plotting a figure where I need two independent x axes and two
> independent y axes. I've tried to use both twinx and twiny at the
> same time, and this works to some extent, but it looks like it is
> plotting the labels for the bottom x axis and the right-hand y axis
> twice, which makes me think that I must be doing something wrong (the
> numbers appear more 'bold'). The code is below. Is there a better way
> to do this?
>
> In reality, I don't need a different scale for the opposite axes, but
> I want to specify different Locator functions, but I assume that
> creating a new axes instance as done below is the only way to do this?
>
> Thanks for any advice,
>
> Thomas
>
> ###
> fig = figure()
> ax  = fig.add_subplot(111)
> ax2 = ax.twinx().twiny()
> for tick in ax.yaxis.get_major_ticks():
>tick.label1On = True
>tick.label2On = False
>tick.tick1On = True
>tick.tick2On = False
> for tick in ax.xaxis.get_major_ticks():
>tick.label1On = True
>tick.label2On = False
>tick.tick1On = True
>tick.tick2On = False
> for tick in ax2.yaxis.get_major_ticks():
>tick.label1On = False
>tick.label2On = True
>tick.tick1On = False
>tick.tick2On = True
> for tick in ax2.xaxis.get_major_ticks():
>tick.label1On = False
>tick.label2On = True
>tick.tick1On = False
>tick.tick2On = True
> ax.scatter([0.4],[0.6])
> ax2.scatter([10.],[10.])
> draw()
> ###
>
>
> --
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] title pad?

2009-02-08 Thread C M
Is there anything like a title pad, similar to the xaxis.LABELPAD?
I'd like to see if the plot would look better with the title a bit higher
off the plot.

Thanks,
Che

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] title pad?

2009-02-08 Thread Jae-Joon Lee
As far as I know, there is no user settable attribute. But something
like below will work.

ax = gca()
title("My title")

ax.titleOffsetTrans._t = (0., 10.0/72.) # x, y offset in points/72.
default is (0., 5/72.)
ax.titleOffsetTrans.invalidate()

draw()

Alternatively, you may use

ax.title.set_y(1.1) # y position of the title in the normalized axes
coordinate. default 1.0

-JJ




On Mon, Feb 9, 2009 at 2:08 AM, C M  wrote:
> Is there anything like a title pad, similar to the xaxis.LABELPAD?
> I'd like to see if the plot would look better with the title a bit higher
> off the plot.
>
> Thanks,
> Che
>
> --
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users