Re: [Matplotlib-users] matplotlib and pyside..

2011-07-20 Thread Gerald Storer

Have a closer look at the example I gave.

The currently released version of matplotlib doesn't support PySide at 
all.  So I cheated and simply drew to the generic Agg backend and then 
copied the whole figure (gcf = get current figure) into a PySide QImage 
object at the end.  The QImage can then be displayed however you want 
inside your Qt application.  I used a QGraphicsScene but there are other 
options.


If you really wanted to I guess you could use FigureCanvasAgg as an 
intermediary - but the process is fundamentally different.  You can't 
just drop that it into your PySide app as a widget like you can with 
FigureCanvasQTAgg.


As mentioned earlier, if you'd like to use the same code simply wait for 
the next release of matplotlib which will support PySide or you can get 
a copy of the source from github master today that also support PySide.


Gerald.

On 20/07/2011 3:59 PM, lionel chiron wrote:

Hi Gerald,

I found yesterday interesting informations on a forum where you 
answered about Matplotlib and pyside .. but some details are missing 
to make what I want.
Few days ago I developped stuff in PyQt I 'd like to recuperate in 
Pyside.. the central difficulty is to import Matplotlib in Pyside.
In PyQt I was using FigureCanvasQTAgg but in Pyside I couldn't find 
something equivalent allowing to link Mpl and pyside..
It seems you're able to make drawings (with add.patch) but how to do 
for inserting a figure?


Thanks

Best

Lionel



--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks  Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib and pyside..

2011-07-20 Thread Gerald Storer
The version of PySide doesn't really matter so long as it is reasonably 
new.  You need a newer version of Matplotlib and yes, the Github master 
is newer than the current release.


Gerald.

On 20/07/2011 8:29 PM, lionel chiron wrote:

Hi Gerald again,

I recuperated the Pyside last version the 1.0.4 from Pyside's site but 
I obtained the same error message trying to use my former code (same 
used with PyQt with Figure Canvas)

raise ImportError, Warning: formlayout requires PyQt4v4.3
Is the github version even more recent than this one??
Thanks

Regards
Lionel


2011/7/20 Gerald Storer g...@mrxtech.com.au mailto:g...@mrxtech.com.au

Have a closer look at the example I gave.

The currently released version of matplotlib doesn't support
PySide at all.  So I cheated and simply drew to the generic Agg
backend and then copied the whole figure (gcf = get current
figure) into a PySide QImage object at the end.  The QImage can
then be displayed however you want inside your Qt application.  I
used a QGraphicsScene but there are other options.

If you really wanted to I guess you could use FigureCanvasAgg as
an intermediary - but the process is fundamentally different.  You
can't just drop that it into your PySide app as a widget like you
can with FigureCanvasQTAgg.

As mentioned earlier, if you'd like to use the same code simply
wait for the next release of matplotlib which will support PySide
or you can get a copy of the source from github master today that
also support PySide.

Gerald.


On 20/07/2011 3:59 PM, lionel chiron wrote:

Hi Gerald,

I found yesterday interesting informations on a forum where you
answered about Matplotlib and pyside .. but some details are
missing to make what I want.
Few days ago I developped stuff in PyQt I 'd like to recuperate
in Pyside.. the central difficulty is to import Matplotlib in
Pyside.
In PyQt I was using FigureCanvasQTAgg but in Pyside I couldn't
find something equivalent allowing to link Mpl and pyside..
It seems you're able to make drawings (with add.patch) but how to
do for inserting a figure?

Thanks

Best

Lionel







--
5 Ways to Improve  Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib + pyside

2011-07-14 Thread Gerald Storer
As Eric said Github master works with PySide.  If you can't wait for a 
release and you don't want to run the Github version of MPL you can use 
the following code to render a plot inside a PySide app.  Note that this 
will just show the plot image.  You won't get the tool bar, status bar 
or any other GUI elements.


Gerald.

On 14/07/2011 3:33 PM, Eric Firing wrote:

On 07/13/2011 09:18 PM, Armagan Tarim wrote:

Hi All,
I have tried the sample PySide code given at
http://www.scipy.org/Cookbook/Matplotlib/PySide
the below excerpt is from my Python Shell for this sample code, which
gives this error,

Github master works with pyside.  It is expected to emerge as a release
within a few weeks.

Eric


ImportError: Warning: formlayout requires PyQt4v4.3
It seems that it is looking for PyQt; but the whole point of using
PySide is to avoid using PyQt.
Any help is appreciated.
-- Armagan
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
(Intel)] on win32
Type copyright, credits or license() for more information.
import sys
import matplotlib
matplotlib.use('Qt4Agg')
import pylab
Traceback (most recent call last):
File pyshell#3, line 1, inmodule
import pylab
File C:\Python27\lib\site-packages\pylab.py, line 1, inmodule
from matplotlib.pylab import *
File C:\Python27\lib\site-packages\matplotlib\pylab.py, line 263, in
module
from matplotlib.pyplot import *
File C:\Python27\lib\site-packages\matplotlib\pyplot.py, line 95, in
module
new_figure_manager, draw_if_interactive, show = pylab_setup()
File C:\Python27\lib\site-packages\matplotlib\backends\__init__.py,
line 25, in pylab_setup
globals(),locals(),[backend_name])
File
C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4agg.py,
line 12, inmodule
from backend_qt4 import QtCore, QtGui, FigureManagerQT, FigureCanvasQT,\
File C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4.py,
line 18, inmodule
import matplotlib.backends.qt4_editor.figureoptions as figureoptions
File
C:\Python27\lib\site-packages\matplotlib\backends\qt4_editor\figureoptions.py,
line 11, inmodule
import matplotlib.backends.qt4_editor.formlayout as formlayout
File
C:\Python27\lib\site-packages\matplotlib\backends\qt4_editor\formlayout.py,
line 51, inmodule
raise ImportError, Warning: formlayout requires PyQt4v4.3
ImportError: Warning: formlayout requires PyQt4v4.3

-




import numpy as np
from matplotlib import use
use('AGG')
from matplotlib.transforms import Bbox
from matplotlib.path import Path
from matplotlib.patches import Rectangle
from matplotlib.pylab import *
from PySide import QtCore,QtGui


rect = Rectangle((-1, -1), 2, 2, facecolor=#aa)
gca().add_patch(rect)
bbox = Bbox.from_bounds(-1, -1, 2, 2)

for i in range(12):
vertices = (np.random.random((4, 2)) - 0.5) * 6.0
vertices = np.ma.masked_array(vertices, [[False, False], [True, True], 
[False, False], [False, False]])
path = Path(vertices)
if path.intersects_bbox(bbox):
color = 'r'
else:
color = 'b'
plot(vertices[:,0], vertices[:,1], color=color)


app = QtGui.QApplication(sys.argv)
gcf().canvas.draw()

stringBuffer = gcf().canvas.buffer_rgba(0,0)
l, b, w, h = gcf().bbox.bounds

qImage = QtGui.QImage(stringBuffer, 
  w,
  h,
  QtGui.QImage.Format_ARGB32)

scene = QtGui.QGraphicsScene()
view = QtGui.QGraphicsView(scene)
pixmap = QtGui.QPixmap.fromImage(qImage)
pixmapItem = QtGui.QGraphicsPixmapItem(pixmap)
scene.addItem(pixmapItem)
view.show()

app.exec_()
--
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on Lean Startup 
Secrets Revealed. This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Where to search with mailing list archive

2011-05-18 Thread Gerald Storer

There's a heap of searches - the old.nabble one listed.
http://old.nabble.com/matplotlib---users-f2906.html
plus
http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/info.html
http://blog.gmane.org/gmane.comp.python.matplotlib.general
http://www.mailinglistarchive.com/html/matplotlib-users@lists.sourceforge.net/

I find google to be better at figuring out what you want though.  So a 
google search like:

search terms site:old.nabble.com intitle:matplotlib intitle:users
tends to work better.

Gerald.

On 18/05/2011 10:55 PM, Benjamin Root wrote:



On Wed, May 18, 2011 at 5:52 AM, Yue Chao chaoyue...@gmail.com 
mailto:chaoyue...@gmail.com wrote:


Thank you Mark!

If there is no search engine, we'll not make full use of FAQ
history...

Chao


There is a search feature provided by nabble here:

http://old.nabble.com/matplotlib---users-f2906.html

Don't know how good it is, but it does exist.

Ben Root


--
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay


___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users



--
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Animating plots with the Qt backend

2011-05-05 Thread Gerald Storer

Ah,
I did not know that. I shall investigate.

Thanks,
Gerald.

On 6/05/2011 7:27 AM, Benjamin Root wrote:



On Tue, May 3, 2011 at 3:57 AM, Gerald Storer g...@mrxtech.com.au 
mailto:g...@mrxtech.com.au wrote:


Hello,

I've been trying to animate some plots with the qt backend and run
into
a couple of problems.

Firstly,
I'd like to be able to update the axis limits in an automated
fashion as
the data changes size.

Secondly,
Resizing figures appears to redraw everything _but_ items with the
animation flag.  The is causing me problems when the animation is
paused
or the frames are occurring slow enough such that there is a noticable
period where the my lines disappear.

I've sort of solved both of these problems but the solutions seem
hackish.  In particular updating the axis limits is slowing the
animation by 25% and toggling the animated field using the qt events
just feels like its asking for trouble.

Below is the qt animation example with my solutions.  Adjust the
size of
the plot after the animation finishes to see the effect of the resize
hack.  I would be grateful if anyone could suggest some improvements.

Thanks,
Gerald.

# For detailed comments on animation and the techniqes used here, see

# the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations

import os

import sys

#import matplotlib

#matplotlib.use('Qt4Agg')

from matplotlib.figure import Figure

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
as FigureCanvas

from PyQt4 import QtCore, QtGui

ITERS = 100

import numpy as np

import time

class BlitQT(FigureCanvas):

def __init__(self):

FigureCanvas.__init__(self, Figure())

self.ax http://self.ax = self.figure.add_subplot(111)

#self.ax.grid()

self.draw()

self.old_size = self.ax.bbox.width, self.ax.bbox.height

self.ax_background = self.copy_from_bbox(self.ax.bbox)

self.cnt = 0

self.x = np.arange(0,2*np.pi,0.01)

self.sin_line, = self.ax.plot(self.x, np.sin(self.x),
animated=True)

self.cos_line, = self.ax.plot(self.x, np.cos(self.x),
animated=True)

self.draw()

self.old_limits = self.ax.get_xlim(),self.ax.get_ylim()

self.tstart = time.time()

self.maintimer = self.startTimer(10)

## HACK for disapearing objects on resize

def resizeEvent(self,evt):

super(BlitQT,self).resizeEvent(evt)

self.sin_line.set_animated(False)

def paintEvent(self,evt):

super(BlitQT,self).paintEvent(evt)

self.sin_line.set_animated(True)

def timerEvent(self, evt):

current_size = self.ax.bbox.width, self.ax.bbox.height

if self.old_size != current_size:

self.old_size = current_size

#self.ax.clear()

#self.ax.grid()

self.draw()

self.ax_background = self.copy_from_bbox(self.ax.bbox)

self.restore_region(self.ax_background)

# update the data

   
self.sin_line.set_ydata(np.sin(self.x+self.cnt/10.0)*self.cnt/100.0)


   
self.cos_line.set_ydata(np.cos(self.x+self.cnt/10.0)*self.cnt/100.0)


## HACK for updating axis limits

self.ax.relim()

self.ax.autoscale_view()

current_limits = self.ax.get_xlim(),self.ax.get_ylim()

if self.old_limits != current_limits:

self.old_limits = current_limits

self.draw()

self.ax_background = self.copy_from_bbox(self.ax.bbox)

self.blit(self.figure.bbox)



# just draw the animated artist

self.ax.draw_artist(self.sin_line)

self.ax.draw_artist(self.cos_line)

# just redraw the axes rectangle

self.blit(self.ax.bbox)

if self.cnt == 0:

# TODO: this shouldn't be necessary, but if it is
excluded the

# canvas outside the axes is not initially painted.

self.draw()

if self.cnt==ITERS:

# print the timing info and quit

print 'FPS:' , ITERS/(time.time()-self.tstart)

#sys.exit()

self.killTimer(self.maintimer)

else:

self.cnt += 1

app = QtGui.QApplication(sys.argv)

widget = BlitQT()

widget.show()

sys.exit(app.exec_())


Gerald,

I haven't looked at your code, but I would like to point out that if 
you wish to experiment a little further with animations in matplotlib, 
there is a animation module that is in the  current development branch 
(but has not been officially released).  Maybe using it might help 
make your code

[Matplotlib-users] Animating plots with the Qt backend

2011-05-03 Thread Gerald Storer
Hello,

I've been trying to animate some plots with the qt backend and run into 
a couple of problems.

Firstly,
I'd like to be able to update the axis limits in an automated fashion as 
the data changes size.

Secondly,
Resizing figures appears to redraw everything _but_ items with the 
animation flag.  The is causing me problems when the animation is paused 
or the frames are occurring slow enough such that there is a noticable 
period where the my lines disappear.

I've sort of solved both of these problems but the solutions seem 
hackish.  In particular updating the axis limits is slowing the 
animation by 25% and toggling the animated field using the qt events 
just feels like its asking for trouble.

Below is the qt animation example with my solutions.  Adjust the size of 
the plot after the animation finishes to see the effect of the resize 
hack.  I would be grateful if anyone could suggest some improvements.

Thanks,
Gerald.

# For detailed comments on animation and the techniqes used here, see

# the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations

import os

import sys

#import matplotlib

#matplotlib.use('Qt4Agg')

from matplotlib.figure import Figure

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

from PyQt4 import QtCore, QtGui

ITERS = 100

import numpy as np

import time

class BlitQT(FigureCanvas):

 def __init__(self):

 FigureCanvas.__init__(self, Figure())

 self.ax = self.figure.add_subplot(111)

 #self.ax.grid()

 self.draw()

 self.old_size = self.ax.bbox.width, self.ax.bbox.height

 self.ax_background = self.copy_from_bbox(self.ax.bbox)

 self.cnt = 0

 self.x = np.arange(0,2*np.pi,0.01)

 self.sin_line, = self.ax.plot(self.x, np.sin(self.x), animated=True)

 self.cos_line, = self.ax.plot(self.x, np.cos(self.x), animated=True)

 self.draw()

 self.old_limits = self.ax.get_xlim(),self.ax.get_ylim()

 self.tstart = time.time()

 self.maintimer = self.startTimer(10)

 ## HACK for disapearing objects on resize

 def resizeEvent(self,evt):

 super(BlitQT,self).resizeEvent(evt)

 self.sin_line.set_animated(False)

 def paintEvent(self,evt):

 super(BlitQT,self).paintEvent(evt)

 self.sin_line.set_animated(True)

 def timerEvent(self, evt):

 current_size = self.ax.bbox.width, self.ax.bbox.height

 if self.old_size != current_size:

 self.old_size = current_size

 #self.ax.clear()

 #self.ax.grid()

 self.draw()

 self.ax_background = self.copy_from_bbox(self.ax.bbox)

 self.restore_region(self.ax_background)

 # update the data

 self.sin_line.set_ydata(np.sin(self.x+self.cnt/10.0)*self.cnt/100.0)

 self.cos_line.set_ydata(np.cos(self.x+self.cnt/10.0)*self.cnt/100.0)

 ## HACK for updating axis limits

 self.ax.relim()

 self.ax.autoscale_view()

 current_limits = self.ax.get_xlim(),self.ax.get_ylim()

 if self.old_limits != current_limits:

 self.old_limits = current_limits

 self.draw()

 self.ax_background = self.copy_from_bbox(self.ax.bbox)

 self.blit(self.figure.bbox)

  

 # just draw the animated artist

 self.ax.draw_artist(self.sin_line)

 self.ax.draw_artist(self.cos_line)

 # just redraw the axes rectangle

 self.blit(self.ax.bbox)

 if self.cnt == 0:

 # TODO: this shouldn't be necessary, but if it is excluded the

 # canvas outside the axes is not initially painted.

 self.draw()

 if self.cnt==ITERS:

 # print the timing info and quit

 print 'FPS:' , ITERS/(time.time()-self.tstart)

 #sys.exit()

 self.killTimer(self.maintimer)

 else:

 self.cnt += 1

app = QtGui.QApplication(sys.argv)

widget = BlitQT()

widget.show()

sys.exit(app.exec_())



--
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users