Re: [Matplotlib-users] Unknown projection '3d' even with svn version?

2010-11-18 Thread Eric Emsellem
Ok problem(s) solved, thanks a lot for the efficient help (this also taught me 
how to go through the code more thoroughly)

* for the record: I had a pylab.py in the site-packages directory, probably a 
left-over from some other installation, which was interfering with the pylab.py 
which should be the one under matplotlib/. I just removed it now and it works 
well.

* and you were right, the funny "try this" was a left over of many tests I had 
done to track down the problem (mea culpa on that one)

thanks again, all works beautifully (and consistently) now.

cheers
Eric

--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] colorbar settings with a object oriented approach (or mixed pyplot)

2010-11-18 Thread John
Folks, I was trying to use an object oriented approach to creating
colorbars, but I could manage to make it work. Currently I have close
to what I am trying to achieve, but the last bits are missing. The
outstanding issues are:

1) I only need one colorbar, how would I create a single colorbar on
the right that spanned across all axes? (ie. same height as the stack)
2) is there a way to place the colorbar in the bottom middle of my
panels (if I end up with more than one)?
3) How can I customize the tick labels of the colorbar?
4) Is this a 'pythonic' approach to begin with?

Here's my code, and a fake class that should provide the data needed
to use the example:

#!/usr/bin/env python

"""
Demo to help understand plotting tools
"""
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

class Fun(object):
""" Dummy class for testing
"""

class body:
pass

def __init__(self):

body = Fun.body
body.time = np.arange(1000)
body.alt = np.sin(body.time)
body.A = 360*np.random.random_sample(1000)-180
body.B = 180*np.random.random_sample(1000)-90
body.C = 90*np.random.random_sample(1000)-45


def plot_angles(F):
""" Plots the angles of body """

from mpl_toolkits.axes_grid1.inset_locator import inset_axes

# Set up plotting environment colors
Nc = np.arange(-180,181,1)
norm = mpl.colors.normalize(Nc.min(),Nc.max())

fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=True)


ax1.scatter(F.body.time,F.body.alt,c=F.body.A,norm=norm,label='A',edgecolor='none')


ax2.scatter(F.body.time,F.body.alt,c=F.body.B,norm=norm,label='B',edgecolor='none')


ax3.scatter(F.body.time,F.body.alt,c=F.body.C,norm=norm,label='C',edgecolor='none')

# Fine-tune figure; make subplots close to each other and hide x ticks for
# all but bottom plot.
fig.subplots_adjust(hspace=0)
plt.setp([a.get_xticklabels() for a in fig.axes[:-1]], visible=False)
for a in fig.axes:
ia = inset_axes(a,width="20%", height="5%", loc=4)
a.set_xlim(F.body.time[0],F.body.time[-1])
fig.add_subplot(a)
plt.colorbar(a.collections[0],cax=ia,orientation='horizontal')
ia.xaxis.set_ticks_position("top")

plt.draw()

return fig


def demo():

F = Fun()
plot_angles(F)

if __name__ == "__main__":
fig = demo()
plt.show()

--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] date plot with two y axes...and some other things

2010-11-18 Thread C M
Goals:  date plot with two y axes (plotting completely different things)
point picking and point labeling
As many lines as user wants, all colored differently.

Having some problems with this.  (matplotlib 0.98.5)

1) There is a known bug with twinx() and plot_date:

http://sourceforge.net/tracker/index.php?func=detail&aid=3046812&group_id=80706&atid=560720

But I can get it to work if I change ONE OF the plot_date() calls (the
one for the values plotted to the right-hand y axis) to just plot().

Is that going to introduce problems?  Is there a better workaround?
(The ones on that page don't work for me).

2) How can I get the lines belonging to different axes to cycle
through colors such that the same color is not used for any lines
shown in the plot?  (that is, I don't want to hard code a color to any
line, I want it to auto-cycle).

3) My point picking is not working with the two axes.  In my routine,
I label  the picked point and to do that I have to make reference to
its axis and call plot_date().  How can I know which axis the picked
point came from, so that I can label it appropriately?

Sorry this is a little stirred together, but hoping I can get some
hints to allow me to work it into shape.

Thanks,
Che

--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Possible memory leak?

2010-11-18 Thread Caleb Constantine
Matplotlib Users:

It seems matplotlib plotting has a relatively small memory leak. My
experiments suggest it leaks between 5K and 8K bytes of RAM for ever plot
redraw. For example, in one experiment, plotting the same buffer (so as to
not
allocate new memory) every second for a period of about 12 hours resulted in
memory usage (physical RAM) increasing by approximately 223MB, which is
about
5.3K per replot.  The plotting code is:

class PlotPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY,
style=wx.BORDER_THEME|wx.TAB_TRAVERSAL)
self._figure = MplFigure(dpi=None)
self._canvas = MplCanvas(self, -1, self._figure)
self._axes = self._figure.add_subplot(1,1,1)

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self._canvas, 1, wx.EXPAND|wx.TOP, 5)
self.SetSizer(sizer)

def draw(self, channel, seconds):
self._axes.clear()
self._axes.plot(channel, seconds)
self._canvas.draw()


`draw()` is called every second with the same `channels` and `seconds`
numpy.array buffers.

In my case, this leak, though relatively small, becomes a serious issue
since
my software often runs for long periods of time (days) plotting data
streamed
from a data acquisition unit.

Any suggestions will help. Am I miss understanding something here? Maybe I
need to call some obscure function to free memory, or something?

My testing environment:

  * Windws XP SP3, Intel Core 2 Duo @ 2.33GHz, 1.96 GB RAM
  * Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit
(Intel)] on win32
  * matplotlib version 1.0.0
  * numpy 1.4.1
  * wxPython version 2.8.11.0

The complete test program follows.

Thanks,

Caleb


from random import random
from datetime import datetime
import os
import time
import win32api
import win32con
import win32process

import wx
import numpy

import matplotlib as mpl
from matplotlib.figure import Figure as MplFigure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as MplCanvas

def get_process_memory_info(process_id):
memory = {}
process = None
try:
process = win32api.OpenProcess(
win32con.PROCESS_QUERY_INFORMATION|win32con.PROCESS_VM_READ,
False, process_id);
if process is not None:
return win32process.GetProcessMemoryInfo(process)
finally:
if process:
win32api.CloseHandle(process)
return memory

meg = 1024.0 * 1024.0

class PlotPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY,
style=wx.BORDER_THEME|wx.TAB_TRAVERSAL)
self._figure = MplFigure(dpi=None)
self._canvas = MplCanvas(self, -1, self._figure)
self._axes = self._figure.add_subplot(1,1,1)

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self._canvas, 1, wx.EXPAND|wx.TOP, 5)
self.SetSizer(sizer)

def draw(self, channel, seconds):
self._axes.clear()
self._axes.plot(channel, seconds)
self._canvas.draw()

class TestFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(
self, parent, id, title, wx.DefaultPosition, (600, 400))

self.testDuration = 60 * 60 * 24
self.startTime = 0

self.channel = numpy.sin(numpy.arange(1000) * random())
self.seconds = numpy.arange(len(self.channel))

self.plotPanel = PlotPanel(self)

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.plotPanel, 1 ,wx.EXPAND)
self.SetSizer(sizer)

self._timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self._onTimer, self._timer)
self._timer.Start(1000)
print "starting memory: ",\
get_process_memory_info(os.getpid())["WorkingSetSize"]/meg

def _onTimer(self, evt):
if self.startTime == 0:
self.startTime = time.time()

if (time.time() - self.startTime) >= self.testDuration:
self._timer.Stop()

self.plotPanel.draw(self.channel, self.seconds)

t = datetime.now()
memory = get_process_memory_info(os.getpid())
print "time: {0}, working: {1:f}".format(
t, memory["WorkingSetSize"]/meg)

class MyApp(wx.App):
def OnInit(self):
frame = TestFrame(None, wx.ID_ANY, "Memory Leak")
self.SetTopWindow(frame)
frame.Show(True)
return True

if __name__ == '__main__':
app = MyApp(0)
app.MainLoop()
--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev___
Matplotlib-users maili

Re: [Matplotlib-users] Possible memory leak?

2010-11-18 Thread Benjamin Root
On Thu, Nov 18, 2010 at 1:11 PM, Caleb Constantine wrote:

> Matplotlib Users:
>
> It seems matplotlib plotting has a relatively small memory leak. My
> experiments suggest it leaks between 5K and 8K bytes of RAM for ever plot
> redraw. For example, in one experiment, plotting the same buffer (so as to
> not
> allocate new memory) every second for a period of about 12 hours resulted
> in
> memory usage (physical RAM) increasing by approximately 223MB, which is
> about
> 5.3K per replot.  The plotting code is:
>
> class PlotPanel(wx.Panel):
> def __init__(self, parent):
> wx.Panel.__init__(self, parent, wx.ID_ANY,
> style=wx.BORDER_THEME|wx.TAB_TRAVERSAL)
> self._figure = MplFigure(dpi=None)
> self._canvas = MplCanvas(self, -1, self._figure)
> self._axes = self._figure.add_subplot(1,1,1)
>
> sizer = wx.BoxSizer(wx.VERTICAL)
> sizer.Add(self._canvas, 1, wx.EXPAND|wx.TOP, 5)
> self.SetSizer(sizer)
>
> def draw(self, channel, seconds):
> self._axes.clear()
> self._axes.plot(channel, seconds)
> self._canvas.draw()
>
>
> `draw()` is called every second with the same `channels` and `seconds`
> numpy.array buffers.
>
> In my case, this leak, though relatively small, becomes a serious issue
> since
> my software often runs for long periods of time (days) plotting data
> streamed
> from a data acquisition unit.
>
> Any suggestions will help. Am I miss understanding something here? Maybe I
> need to call some obscure function to free memory, or something?
>
> My testing environment:
>
>   * Windws XP SP3, Intel Core 2 Duo @ 2.33GHz, 1.96 GB RAM
>   * Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit
> (Intel)] on win32
>   * matplotlib version 1.0.0
>   * numpy 1.4.1
>   * wxPython version 2.8.11.0
>
> The complete test program follows.
>
> Thanks,
>
> Caleb
>
>
>  from random import random
> from datetime import datetime
> import os
> import time
> import win32api
> import win32con
> import win32process
>
> import wx
> import numpy
>
> import matplotlib as mpl
> from matplotlib.figure import Figure as MplFigure
> from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as
> MplCanvas
>
> def get_process_memory_info(process_id):
> memory = {}
> process = None
> try:
> process = win32api.OpenProcess(
> win32con.PROCESS_QUERY_INFORMATION|win32con.PROCESS_VM_READ,
> False, process_id);
> if process is not None:
> return win32process.GetProcessMemoryInfo(process)
> finally:
> if process:
> win32api.CloseHandle(process)
> return memory
>
> meg = 1024.0 * 1024.0
>
> class PlotPanel(wx.Panel):
> def __init__(self, parent):
> wx.Panel.__init__(self, parent, wx.ID_ANY,
> style=wx.BORDER_THEME|wx.TAB_TRAVERSAL)
> self._figure = MplFigure(dpi=None)
> self._canvas = MplCanvas(self, -1, self._figure)
> self._axes = self._figure.add_subplot(1,1,1)
>
> sizer = wx.BoxSizer(wx.VERTICAL)
> sizer.Add(self._canvas, 1, wx.EXPAND|wx.TOP, 5)
> self.SetSizer(sizer)
>
> def draw(self, channel, seconds):
> self._axes.clear()
> self._axes.plot(channel, seconds)
> self._canvas.draw()
>
> class TestFrame(wx.Frame):
> def __init__(self, parent, id, title):
> wx.Frame.__init__(
> self, parent, id, title, wx.DefaultPosition, (600, 400))
>
> self.testDuration = 60 * 60 * 24
> self.startTime = 0
>
> self.channel = numpy.sin(numpy.arange(1000) * random())
> self.seconds = numpy.arange(len(self.channel))
>
> self.plotPanel = PlotPanel(self)
>
> sizer = wx.BoxSizer(wx.VERTICAL)
> sizer.Add(self.plotPanel, 1 ,wx.EXPAND)
> self.SetSizer(sizer)
>
> self._timer = wx.Timer(self)
>  self.Bind(wx.EVT_TIMER, self._onTimer, self._timer)
> self._timer.Start(1000)
> print "starting memory: ",\
> get_process_memory_info(os.getpid())["WorkingSetSize"]/meg
>
> def _onTimer(self, evt):
> if self.startTime == 0:
> self.startTime = time.time()
>
> if (time.time() - self.startTime) >= self.testDuration:
> self._timer.Stop()
>
> self.plotPanel.draw(self.channel, self.seconds)
>
> t = datetime.now()
> memory = get_process_memory_info(os.getpid())
> print "time: {0}, working: {1:f}".format(
> t, memory["WorkingSetSize"]/meg)
>
> class MyApp(wx.App):
> def OnInit(self):
> frame = TestFrame(None, wx.ID_ANY, "Memory Leak")
> self.SetTopWindow(frame)
> frame.Show(True)
> return True
>
> if __name__ == '__main__':
> app = MyApp(0)
> app.MainLoop()
>
>
>
Caleb,

Interesting analysis.  One possible source of a leak would be some sort of
dangling refere

Re: [Matplotlib-users] Possible memory leak?

2010-11-18 Thread John Hunter
On Thu, Nov 18, 2010 at 2:20 PM, Benjamin Root  wrote:

> Interesting analysis.  One possible source of a leak would be some sort of
> dangling reference that still hangs around even though the plot objects have
> been cleared.  By the time of the matplotlib 1.0.0 release, we did seem to
> clear out pretty much all of these, but it is possible there are still some
> lurking about.  We should probably run your script against the latest svn to
> see how the results compare.

In our experience, many of the GUI backends have some leak, and these
are in the GUI and not in mpl.  Caleb, can you see if you can
replicate the leak with your example code using the agg backend (no
GUI).  If so, could you post the code that exposes the leak.  if not,
I'm afraid it is in wx and you might need to deal with the wx
developers.

JDH

--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Possible memory leak?

2010-11-18 Thread Robert Kern
On 11/18/10 5:05 PM, John Hunter wrote:
> On Thu, Nov 18, 2010 at 2:20 PM, Benjamin Root  wrote:
>
>> Interesting analysis.  One possible source of a leak would be some sort of
>> dangling reference that still hangs around even though the plot objects have
>> been cleared.  By the time of the matplotlib 1.0.0 release, we did seem to
>> clear out pretty much all of these, but it is possible there are still some
>> lurking about.  We should probably run your script against the latest svn to
>> see how the results compare.
>
> In our experience, many of the GUI backends have some leak, and these
> are in the GUI and not in mpl.  Caleb, can you see if you can
> replicate the leak with your example code using the agg backend (no
> GUI).  If so, could you post the code that exposes the leak.  if not,
> I'm afraid it is in wx and you might need to deal with the wx
> developers.

Heh. Good timing! I just fixed a bug in Chaco involving a leaking cycle that 
the 
garbage collector could not clean up. The lesson of my tale of woe is that even 
if there is no leak when you run without wxPython, that doesn't mean that 
wxPython is the culprit.

If any object in the connected graph containing a cycle (even if it does not 
directly participate in the cycle) has an __del__ method in pure Python, then 
the garbage collector will not clean up that cycle for safety reasons. Read the 
docs for the gc module for details. We use SWIG to wrap Agg and SWIG adds 
__del__ methods for all of its classes. wxPython uses SWIG and has the same 
problems. If there is a cycle which can reach a wxPython object, the cycle will 
leak. The actual cycle may be created by matplotlib, though.

You can determine if this is the case pretty easily, though. Call gc.collect() 
then examine the list gc.garbage. This will contain all of those objects with a 
__del__ that prevented a cycle from being collected.

I recommend using objgraph to diagram the graph of references to those objects. 
It's invaluable to actually see what's going on.

   http://pypi.python.org/pypi/objgraph

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco


--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] set font properties for colorbar

2010-11-18 Thread John
Hello,

I see that for a legend you can do the following:

ax = plt.scatter(x,y,label='test data')
p_leg = mpl.font_manager.FontProperties(size='8')
ax.legend(prop=p_leg)

But, how do you do set font properties for the colorbar tick labels?

Thanks!

--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Control of thread/program not returning to ipython after creating a plot.

2010-11-18 Thread Collin Day
So I tried updating and rebuilding Matplotlib - no luck - something (at
least on my system) is goofy with the GTK(Agg),WX(Agg), and
Fltk(Agg) backends.  But the TkAgg backend works great.  So I will
stick with that, but if anyone else sees this problem and it becomes an
issue, I'd be happy to help debug it in any way I can.

-C

 On Wed, 17 Nov 2010 19:46:34 -0600
Benjamin Root  wrote:

> On Wed, Nov 17, 2010 at 7:38 PM, Collin Day 
> wrote:
> 
> > On Wed, 17 Nov 2010 19:00:54 -0600
> > Benjamin Root  wrote:
> >
> > Another data point -
> >
> > I tried Qt4Agg - it also works interactively - ie it goes back to
> > the ipython cmd line.  I also noticed when I start ipython --pylab,
> > the following error messages occur:
> >
> > ** Message: pygobject_register_sinkfunc is deprecated (GtkWindow)
> > ** Message: pygobject_register_sinkfunc is deprecated (GtkInvisible)
> > ** Message: pygobject_register_sinkfunc is deprecated (GtkObject)
> >
> >
> Interesting.  It is possible that the gtk backend might have been
> compiled against gtk development libraries that do not match your
> current gtk library.  What have you updated recently, and how did you
> do it?
> 
> Ben Root

--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users