Re: [Matplotlib-users] Clear Figure

2008-10-05 Thread rocha

Hi Jae-Joon Lee,

I tried it but unfortunately it didn't work too. After the Figure is 
cleared I cannot plot again.


I've attached the whole code that I'm trying to do this, I hope it could 
help a little bit. I modified the original example just to test this 
feature.


Thanks!
Bernardo M. Rocha

Jae-Joon Lee wrote:

I guess you need to put draw() after plot()

self.canvas.figure.clf()
self.canvas.axes.plot([1.,2.,4.])
self.canvas.draw()

Let us know if it does not help.

-JJ



On Sat, Oct 4, 2008 at 7:17 PM, rocha [EMAIL PROTECTED] wrote:
  

Hi Guys,

I need to clear the Figure after the user has clicked the some button in
PyQt, but when I try to plot the graphics again nothing appear. In
ipython it works, but when I try it inside my application it does not
work. What am I missing?

Inside my MplCanvas class (actually it is a QWidget - see
embedding_in_qt4.py in matplotlib examples file - user_interface) I have
this code:

self.fig = Figure(figsize=(self.width, self.height), dpi=dpi)

And then in my main application I'm trying to do:

self.canvas.figure.clf()
self.canvas.draw()
self.canvas.axes.plot([1.,2.,4.])

and nothing is plotted. The Figure is totally gray. I tried to do the
same thing in embedding_in_qt4.py example, modifying some parts, but it
didn't work too.

Do you have any suggestions?

Thanks!
Best regards,
Bernardo M. Rocha

-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users




#!/usr/bin/env python

# embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib canvases
#
# Copyright (C) 2005 Florent Rougon
#   2006 Darren Dale
#
# This file is an example program for matplotlib. It may be used and
# modified with no restriction; raw copies as well as modified versions
# may be distributed without limitation.

import sys, os, random
from PyQt4 import QtGui, QtCore

from numpy import arange, sin, pi
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

progname = os.path.basename(sys.argv[0])
progversion = 0.1


class MyMplCanvas(FigureCanvas):
Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)

self.compute_initial_figure()

#
FigureCanvas.__init__(self, fig)
self.setParent(parent)

FigureCanvas.setSizePolicy(self,
   QtGui.QSizePolicy.Expanding,
   QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)

def compute_initial_figure(self):
pass


class MyStaticMplCanvas(MyMplCanvas):
Simple canvas with a sine plot.
def compute_initial_figure(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
self.axes.plot(t, s)


class MyDynamicMplCanvas(MyMplCanvas):
A canvas that updates itself every second with a new plot.
def __init__(self, *args, **kwargs):
MyMplCanvas.__init__(self, *args, **kwargs)
timer = QtCore.QTimer(self)
QtCore.QObject.connect(timer, QtCore.SIGNAL(timeout()), self.update_figure)
timer.start(1000)

def compute_initial_figure(self):
 self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r')

def update_figure(self):
# Build a list of 4 random integers between 0 and 10 (both inclusive)
l = [ random.randint(0, 10) for i in xrange(4) ]

self.axes.plot([0, 1, 2, 3], l, 'r')
self.draw()

def limpa(self):
self.figure.clf()
self.draw()


class ApplicationWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle(application main window)

self.file_menu = QtGui.QMenu('File', self)
self.file_menu.addAction('Quit', self.fileQuit,
 QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
self.menuBar().addMenu(self.file_menu)

self.help_menu = QtGui.QMenu('Help', self)
self.menuBar().addSeparator()
self.menuBar().addMenu(self.help_menu)

self.help_menu.addAction('About', self.teste)

self.main_widget = QtGui.QWidget(self)

l = QtGui.QVBoxLayout(self.main_widget)
sc = 

Re: [Matplotlib-users] Problem in afm.py with 0.98.3

2008-10-05 Thread Jouni K . Seppänen
[EMAIL PROTECTED] (Berthold
Höllmann) writes:

 (Pdb) print self._header
 {'Notice': 'Copyright (c) 1999 Ministry of Education, Taipei, Taiwan. All 
 Rights Reserved.', 'Ascender': 880.0, 'FontBBox': [-123, -250, 1000, 880], 
 'Weight': 'Regular', 'Descender': -250.0, 'CharacterSet': 'Adobe-CNS1-0', 
 'IsFixedPitch': False, 'FontName': 'MOEKai-Regular', 'StartFontMetrics': 
 4.0996, 'CapHeight': 880.0, 'Version': '1.000', 
 'UnderlinePosition': -100, 'Characters': 13699, 'UnderlineThickness': 50, 
 'ItalicAngle': 0.0, 'StartCharMetrics': 13699}

That AFM file doesn't include a family name or a full name for the font
it describes. It seems that both are in fact optional attributes. I have
committed a change (on the trunk, and in the maintenance branch) that
should fix this, but since I don't have any AFM files like this, I can't
check that it works. Can you check out either the trunk or the
maintenance branch from Subversion, or apply the following patch and try
again?

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

Index: lib/matplotlib/afm.py
===
--- lib/matplotlib/afm.py	(revision 6149)
+++ lib/matplotlib/afm.py	(revision 6150)
@@ -34,7 +34,7 @@
   John D. Hunter [EMAIL PROTECTED]
 
 
-import sys, os
+import sys, os, re
 from _mathtext_data import uni2type1
 
 #Convert string the a python type
@@ -433,12 +433,22 @@
 
 def get_fullname(self):
 Return the font full name, eg, 'Times-Roman'
-return self._header['FullName']
+name = self._header.get('FullName')
+if name is None: # use FontName as a substitute
+name = self._header['FontName']
+return name
 
 def get_familyname(self):
 Return the font family name, eg, 'Times'
-return self._header['FamilyName']
+name = self._header.get('FamilyName')
+if name is not None:
+return name
 
+# FamilyName not specified so we'll make a guess
+name = self.get_fullname()
+extras = r'(?i)([ -](regular|plain|italic|oblique|bold|semibold|light|ultralight|extra|condensed))+$'
+return re.sub(extras, '', name)
+
 def get_weight(self):
 Return the font weight, eg, 'Bold' or 'Roman'
 return self._header['Weight']
-
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=100url=/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Problems plotting/closing figures within a thread

2008-10-05 Thread jcarnes

I am writing a GUI application in wxPython and using MPL that plots figures,
saves them to image files, and then closes them all from within a thread to
keep the GUI responsive. Using the Enthought 2.3 install I would
sporatically have crashes that were hard to reproduce, but now that I've
upgrade to Enthought 2.5 (Python 2.5 and MPL 0.91.2.0001) it started
throwing exceptions when attempting to close a figure that I don't
understand. I've created an example script that excites the exception. I'm
not sure if the syptoms are a combination of problems caused by my use of
threads but this problem does not occur if threading is removed from the
script. I've read of others experiencing memory leaks and such when closing
figures, but no situations quite like this.

I am working from a desktop in Windows XP and I use the WXAgg backend.

Does anyone have any ideas, or any feedback on my use of threads? Thanks,
Josh

---
#!/usr/bin/python

import wx
import time
from threading import Thread

import matplotlib
matplotlib.interactive(False)
matplotlib.use('WXAgg')
import matplotlib.pylab

class TestThread(Thread):
def __init__(self, notify_window):
Thread.__init__(self)

def run(self):
while True:  # Continuous loop that plots and destroys a figure
matplotlib.pylab.figure(1)
matplotlib.pylab.plot(range(0,5), range(0,5))
matplotlib.pylab.show()
time.sleep(1)
matplotlib.pylab.close(1)  ### ERROR OCCURS HERE

class MainPanel(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
self.test_thread = None

# GUI objects and bindings
self.run_test_button = wx.Button(self, -1, Run)
self.top_sizer = wx.BoxSizer(wx.VERTICAL)
self.top_sizer.Add(self.run_test_button,  0, wx.EXPAND|wx.ALL,
border=2)
self.SetSizer(self.top_sizer)
self.Bind(wx.EVT_BUTTON,   self.run_test_button_bind,   id =
self.run_test_button.GetId())

### Binding Methods
def run_test_button_bind(self, event):
self.test_thread = TestThread(self)
self.test_thread.start()
#self.test_thread.run()

class MainFrame(wx.Frame):
def __init__(self, *args, **kwargs):
mFrame = wx.Frame.__init__(self, *args, **kwargs)
self.mPanel = MainPanel(self, -1)

class mainApp(wx.App):
def OnInit(self):
self.frame = MainFrame(None, title=Test, size=wx.Size(100, 100))
self.frame.Show()
self.SetTopWindow(self.frame)
return True

if __name__ == __main__:
app = mainApp()
app.MainLoop()

--

Exception in thread Thread-1:
Traceback (most recent call last):
  File C:\Python25\lib\threading.py, line 486, in __bootstrap_inner
self.run()
  File .\test.py, line 22, in run
matplotlib.pylab.close(1)  ### ERROR OCCURS HERE
  File
C:\python25\lib\site-packages\matplotlib-0.91.2.0001-py2.5-win32.egg\matplotlib\pyplot.py,
line 245, in close
_pylab_helpers.Gcf.destroy(arg)
  File
C:\python25\lib\site-packages\matplotlib-0.91.2.0001-py2.5-win32.egg\matplotlib\_pylab_helpers.py,
line 28, in destroy
figManager.destroy()
  File
C:\python25\lib\site-packages\matplotlib-0.91.2.0001-py2.5-win32.egg\matplotlib\backends\backend_wx.py,
line 1406, in destroy
self.frame.Destroy()
  File
C:\python25\lib\site-packages\matplotlib-0.91.2.0001-py2.5-win32.egg\matplotlib\backends\backend_wx.py,
line 1365, in Destroy
wxapp.Yield()
  File
C:\python25\lib\site-packages\wxpython-2.8.4.0.0003_s-py2.5-win32.egg\wx\_core.py,
line 7119, in Yield
return _core_.PyApp_Yield(*args, **kwargs)
PyAssertionError: C++ assertion wxThread::IsMain() failed at
..\..\src\msw\evtloop.cpp(244) in wxEventLoop::Dispatch(): only the main
thread can process Windows messages
-- 
View this message in context: 
http://www.nabble.com/Problems-plotting-closing-figures-within-a-thread-tp19789227p19789227.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Clear Figure

2008-10-05 Thread John Hunter
On Sun, Oct 5, 2008 at 3:50 AM, rocha [EMAIL PROTECTED] wrote:

 self.canvas.figure.clf()
 self.canvas.draw()
 self.canvas.axes.plot([1.,2.,4.])

 and nothing is plotted. The Figure is totally gray. I tried to do the
 same thing in embedding_in_qt4.py example, modifying some parts, but it
 didn't work too.

 Do you have any suggestions?

The problem appears to be that you have kept a copy of your old axes
around (self.canvas.axes is not a mpl construct, so it looks like you
have attached an axes instance to your canvas instance).  You will
want to either not clear your figure and clear your axes instead

  ax.cla()
  ax.plot([1,2,3])
  canvas.draw()

or clear your figure, create a new axes, plot and then draw

   fig.clf()
   ax = fig.add_subplot(111)
   ax.plot([1,2,3])
   ax.draw()

Be careful with the name axes to refer to a single axes instance
attached to your canvas.  In the mpl scheme, axes is a list of Axes
instance and is attached to the Figure instance.  See for example

  http://matplotlib.sourceforge.net/doc/html/users/artists.html

JDH

-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Installation on Fedora2 etc.

2008-10-05 Thread Venkat Ramanan
Hi all,

I'm trying to install the latest matplotlib on a couple of machines.

They both run the same OS (an old custom version between Fedora 2 and 3) 
but the rest of the setup are rather different. For the curious, one is 
an MR scanner and the other is a developmental machine for compiling 
pulse-sequences etc.

I have root permissions on both, but would rather not disturb the 
installed directory tree. What is the best/recommended way of going 
about it?

1. Is it possible to install matplotlib ( and its requirements ) in the 
developmental machine in a separate root directory, export it and mount 
from the other machine? The idea is to install once and use those from 
both. Would this work? What backends would work on this setup?

2. This is to be used for dynamically plotting the data coming out of 
the scanner. I'm also thinking of embedding it in an UI. Can all the UI 
backends handle the rate of about 10 FPS with each data ~5K short-ints?

Thanks for your time,
Venkat.

-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] vertical padding in legend

2008-10-05 Thread Jae-Joon Lee

 Done, except that it just raises a warning, and still works with the old
 kwarg.  The new kwarg is borderpad; it is used if pad==0, which is the new
 rc default.  I set the default borderpad=0.5.

 There is still too much other positioning in legend that is based on axes
 units.  I briefly tried to start changing others, again with additional
 kwargs, and things quickly fell apart.  Legend needs considerable reworking
 to take full advantage of the transforms framework (and maybe other mpl
 improvements since the original legend) and to put all positioning kwargs
 and code in sensible units.  It is amazing that the present code works as
 well as it does.

 The way to make a transition may be via a separate version for a while.
 There could be a single interface, with a kwarg to choose the version.


Thanks Eric.

I would like to help reworking on the legend class.
I once tried to incorporate the FancyBox into the legend but the
result is not satisfactory because the legend bounding box is defined
as axes units in the current implementation (see the attached
screenshot). And I guess it would be better do things in the display
coordinate.

Also, in the current implementation, the vertical spacing between each
legend varies according to the height of the legend text. For example,
in the attached screenshot, the spacings between ac, ag, lg are
all different and this is because their text heights are different. I
think it is better if we have a fixed spacing, or have a minimum
spacing as the text height of lg. And use the baseline-alignment if
possible.

Regards,

-JJ
attachment: t.png-
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=100url=/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Problems plotting/closing figures within a thread

2008-10-05 Thread Vincent Favre-Nicolin
On dimanche 05 octobre 2008, jcarnes wrote:
 I am writing a GUI application in wxPython and using MPL that plots
 figures, saves them to image files, and then closes them all from within a
 thread to keep the GUI responsive.

   Normally only the main thread should alter the graphics - you'll have 
crashes if you try to do it otherwise. If you want to perform calculations in 
a separate thread to keep the GUI responsive, you have to send an event from 
the working thread to the main thread, so that the main thread does the GUI 
update.

http://docs.wxwidgets.org/stable/wx_wxthreadoverview.html#wxthreadoverview

   Well, at least that's the story from my C++ wx knowledge, but it is 
probably still valid in Python.

Another interesting read from the samples page:
http://docs.wxwidgets.org/trunk/page_samples.html#page_samples_thread

  Maybe simply using wxMutexGUIEnter() / wxMutexGUILeave() will sort your 
problems, but I've not tried this method.

Vincent
-- 
Vincent Favre-Nicolin

CEA Grenoble/INAC/SP2M  http://inac.cea.fr
Univ. Joseph Fourier (Grenoble) http://www.ujf-grenoble.fr

ObjCryst  Fox  http://objcryst.sf.net/Fox

-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Colorbar values

2008-10-05 Thread Angus McMorland
Hi all,

I'm trying to plot a colour bar for a scatter plot, and set the
maximum value of the plot to something arbitrary. At the moment it
always comes up as 255. How can I change this?

ax = plt.gca()
pts = ax.scatter(coords[:,0], coords[:,1], c=np.linspace(0,1,n_pts), s=16,
 edgecolors='k', linewidth=1)

Also, there seem to be many different ways to make colorbars associate
with certain objects like the colorbar keyword to scatter perhaps, but
the simplest/only way to create a colorbar that I can get to work is:

ax.figure.colorbar(ax.images[0])

Is there a better way to do this so the vmin and vmax attributes of
the scatter plot get used in the colorbar?

Thanks,

Angus.
-- 
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh

-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] luminocity plot on hammer projection

2008-10-05 Thread dasratsel

Hi,

I've done some poking an I can't find a way to use imshow() to plot a
luminosity map on a hammer projection. (looking to generate a plot like
http://en.wikipedia.org/wiki/Image:WMAP_2008.png). Just setting the
projection in a call to subplot gives some axes and an off-center retangular
image of my array. Bearing in mind that I am completely new to matplotlib,
does anyone have an idea of how to get this sort of plot?

Thanks,
Kris

(PS. Apologies if this shows up in two places, I'm not used to using mailing
lists)
-- 
View this message in context: 
http://www.nabble.com/luminocity-plot-on-hammer-projection-tp19829899p19829899.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] luminocity plot on hammer projection

2008-10-05 Thread Eric Firing
dasratsel wrote:
 Hi,
 
 I've done some poking an I can't find a way to use imshow() to plot a
 luminosity map on a hammer projection. (looking to generate a plot like
 http://en.wikipedia.org/wiki/Image:WMAP_2008.png). Just setting the
 projection in a call to subplot gives some axes and an off-center retangular
 image of my array. Bearing in mind that I am completely new to matplotlib,
 does anyone have an idea of how to get this sort of plot?
 
 Thanks,
 Kris
 
 (PS. Apologies if this shows up in two places, I'm not used to using mailing
 lists)

Kris,

For any sort of mapping like this, you will probably want to use basemap 
matplotlib toolkit, except that I don't see hammer among the supported 
projections.

With straight mpl, imshow does not support projections.  You could use 
pcolor (very slow) or pcolormesh.  In neither case will you get 
interpolation; you will be specifying colored quadrilaterals.

Eric

-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users