[matplotlib-devel] Patch for matplotlib-py3

2011-03-16 Thread Christoph Gohlke

Hello,

please consider the attached patch for the matplotlib-py3 fork on 
github. It corrects some build and test failures and removes unnecessary 
'extern "C"' statements from PyMODINIT_FUNC functions.


From :
Note that PyMODINIT_FUNC declares the function as void return type, 
declares any special linkage declarations required by the platform, and 
for C++ declares the function as extern "C".


Christoph
diff --git a/examples/animation/simple_3danim.py 
b/examples/animation/simple_3danim.py
index 4a59a35..74e918f 100644
--- a/examples/animation/simple_3danim.py
+++ b/examples/animation/simple_3danim.py
@@ -15,7 +15,7 @@ def Gen_RandLine(length, dims=2) :
 """
 lineData = np.empty((dims, length))
 lineData[:, 0] = np.random.rand(dims)
-for index in xrange(1, length) :
+for index in range(1, length) :
 # scaling the random numbers by 0.1 so
 # movement is small compared to position.
 # subtraction by 0.5 is to change the range to [-0.5, 0.5]
diff --git a/examples/event_handling/viewlims.py 
b/examples/event_handling/viewlims.py
index 5bb7bf6..fe5838c 100644
--- a/examples/event_handling/viewlims.py
+++ b/examples/event_handling/viewlims.py
@@ -30,7 +30,7 @@ class MandlebrotDisplay(object):
 threshold_time = np.zeros((self.height, self.width))
 z = np.zeros(threshold_time.shape, dtype=np.complex)
 mask = np.ones(threshold_time.shape, dtype=np.bool)
-for i in xrange(self.niter):
+for i in range(self.niter):
 z[mask] = z[mask]**self.power + c[mask]
 mask = (np.abs(z) < self.radius)
 threshold_time += mask
diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py
index e15c5a8..09aa4ed 100644
--- a/examples/misc/multiprocess.py
+++ b/examples/misc/multiprocess.py
@@ -81,7 +81,7 @@ class NBPlot(object):
 
 def main():
 pl = NBPlot()
-for ii in xrange(10):
+for ii in range(10):
 pl.plot()
 time.sleep(0.5)
 raw_input('press Enter...')
diff --git a/examples/pylab_examples/scatter_star_poly.py 
b/examples/pylab_examples/scatter_star_poly.py
index ae0d207..a3b5831 100644
--- a/examples/pylab_examples/scatter_star_poly.py
+++ b/examples/pylab_examples/scatter_star_poly.py
@@ -13,8 +13,8 @@ plt.subplot(322)
 plt.scatter(x,y,s=80, c=z, marker=(5,0))
 
 verts = list(zip([-1.,1.,1.,-1.],[-1.,-1.,1.,-1.]))
-pylab.subplot(323)
-pylab.scatter(x,y,s=80, c=z, marker=(verts,0))
+plt.subplot(323)
+plt.scatter(x,y,s=80, c=z, marker=(verts,0))
 # equivalent:
 #plt.scatter(x,y,s=80, c=z, marker=None, verts=verts)
 
diff --git a/examples/pylab_examples/simple_plot_fps.py 
b/examples/pylab_examples/simple_plot_fps.py
index 11dba15..5459479 100755
--- a/examples/pylab_examples/simple_plot_fps.py
+++ b/examples/pylab_examples/simple_plot_fps.py
@@ -24,7 +24,7 @@ import time
 frames = 100.0
 t = time.time()
 c = time.clock()
-for i in xrange(int(frames)):
+for i in range(int(frames)):
 part = i / frames
 axis([0.0, 1.0 - part, -1.0 + part, 1.0 - part])
 wallclock = time.time() - t
diff --git a/examples/user_interfaces/embedding_in_qt.py 
b/examples/user_interfaces/embedding_in_qt.py
index c5e0e35..311fd9e 100755
--- a/examples/user_interfaces/embedding_in_qt.py
+++ b/examples/user_interfaces/embedding_in_qt.py
@@ -76,7 +76,7 @@ class MyDynamicMplCanvas(MyMplCanvas):
 
 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) ]
+l = [ random.randint(0, 10) for i in range(4) ]
 
 self.axes.plot([0, 1, 2, 3], l, 'r')
 self.draw()
diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py
index d067d0c..8176071 100644
--- a/lib/matplotlib/figure.py
+++ b/lib/matplotlib/figure.py
@@ -316,6 +316,7 @@ class Figure(Artist):
 """
 allsubplots = np.alltrue([hasattr(ax, 'is_last_row') for ax in 
self.axes])
 if len(self.axes)==1:
+ax = self.get_axes()[0]
 for label in ax.get_xticklabels():
 label.set_ha(ha)
 label.set_rotation(rotation)
diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp
index 200dd18..ecc464d 100644
--- a/src/_backend_agg.cpp
+++ b/src/_backend_agg.cpp
@@ -2441,7 +2441,6 @@ void RendererAgg::init_type()
"restore_region(region, x1, y1, x2, y2, x3, y3)");
 }
 
-extern "C"
 #if PY3K
 PyMODINIT_FUNC
 PyInit__backend_agg(void)
diff --git a/src/_backend_gdk.c b/src/_backend_gdk.c
index 4c50aa2..152554c 100644
--- a/src/_backend_gdk.c
+++ b/src/_backend_gdk.c
@@ -52,7 +52,7 @@ static PyMethodDef _backend_gdk_functions[] = {
 { NULL, NULL, 0 }
 };
 
-DL_EXPORT(void)
+PyMODINIT_FUNC
 init_backend_gdk(void)
 {
 PyObject *mod;
diff --git a/src/_gtkagg.cpp b/src/_gtkagg.cpp
index 5a0b461..60c704a 100644
--- a/src/_gtkagg.cpp
+++ b/src/_gtkagg.cpp
@@ -13

Re: [matplotlib-devel] Backend for Pyside

2011-03-16 Thread Gerald Storer

On 01/18/2011 08:13 PM, Jed Ludlow wrote:
> Please forgive me if I'm raising a heretical question with this since I
> understand the topic of competing Qt bindings for Python gets a little
> touchy in and of itself. Nonetheless, the elephant is in the room. I
> searched the archives and found only a few comments on the subject:
> matplotlib-us...@lists.sourceforge.net/msg18652.html" 
target="_new">http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg18652.html>

> Has there been any additional discussion among the developers about
> creating a formal backend for Pyside?

Its actually a fairly easy to get the PyQt backend working with PySide.  
It would have been laughably easy if not for a couple of bugs in PySide 
that took awhile to track down.


To get it working PySide working you need to:

   * Obviously replace the reference to PyQt with PySide
   * Remove the reference to PyQt/Pyside.Qt and Qt.qApp by replacing it
 with QtGui.qApp (I think this is already done in the most recent
 Git version)
   * Replace the toolbar message signal with a new style signal by:
 o adding 'message = QtCore.Signal(str)' to the
   NavigationToolbar2QT class definition
 o replacing: QtCore.QObject.connect(self.toolbar,
   QtCore.SIGNAL("message"),
 
   self.window.statusBar().showMessage)

   
with:self.toolbar.message.connect(self.window.statusBar().showMessage)
 o replacing: self.emit(QtCore.SIGNAL("message"), s)
   with: self.message.emit(s)
   * Work around the PySide bug with QImage and convert the string
 passed from the Agg backend into a python buffer with
 buffer(stringBuffer) or wait for PySide to fix bug 489.
   * Work around a PySide bug (738) by creating functions to perform
 the slider.setMaxiumum/setMinimum tasks or ignore the runtime
 errors for now and wait for a bug fix.
   * I haven't bothered with the figure options editor at this point -
 I just commented out the references to it.

It might also be a good idea to convert all the signals/slots into the 
new style but it seems to work just fine with only the above changes.


Regards,
Gerald.
--
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel