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 PyQt4>v4.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, in<module>
import pylab
File "C:\Python27\lib\site-packages\pylab.py", line 1, in<module>
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, in<module>
from backend_qt4 import QtCore, QtGui, FigureManagerQT, FigureCanvasQT,\
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4.py",
line 18, in<module>
import matplotlib.backends.qt4_editor.figureoptions as figureoptions
File
"C:\Python27\lib\site-packages\matplotlib\backends\qt4_editor\figureoptions.py",
line 11, in<module>
import matplotlib.backends.qt4_editor.formlayout as formlayout
File
"C:\Python27\lib\site-packages\matplotlib\backends\qt4_editor\formlayout.py",
line 51, in<module>
raise ImportError, "Warning: formlayout requires PyQt4>v4.3"
ImportError: Warning: formlayout requires PyQt4>v4.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="#aaaaaa")
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

Reply via email to