Ok, I upgraded to python 2.6, installed mpl 0.99 qt 4.5, and the new pyqt
and things are more responsive...However, the difference between having that
line in and taking it out are the difference between having pan/zoom events
being extremely responsive and having an extremely noticeable lag. I've
attached a test file from the web which is rather simple. You can notice
the lag if you either try to pan/zoom using the toolbar, or if you try to
use the slider to change the sizes of the horizontal bars.
Sigh, upgrading everything to 2.6 is going to be a chore...
Thanks,
William
On Mon, Aug 31, 2009 at 11:30 AM, Darren Dale <dsdal...@gmail.com> wrote:
> I've been using 2.6. It should be fine on windows now, but I can't
> attest to it since I only use windows when I have to test and make
> windows installers.
>
> On Mon, Aug 31, 2009 at 10:02 AM, william
> ratcliff<william.ratcl...@gmail.com> wrote:
> > Let me try to upgrade to PyQt 4.5--I'm currently using 4.4.3 on vista 32
> > bit. Btw. are you using python 2.6 or 2.5 (I ask because I'm still on
> 2.5
> > and am wondering if anyone has noticed any difficulties with 2.6).
> >
> > Cheers,
> > Wiliam
> >
> > On Mon, Aug 31, 2009 at 9:36 AM, Darren Dale <dsdal...@gmail.com> wrote:
> >>
> >> Hi William,
> >>
> >> On Mon, Aug 31, 2009 at 8:25 AM, william
> >> ratcliff<william.ratcl...@gmail.com> wrote:
> >> > Hi! I just installed matplotlib version .99 (windows vista, python25,
> >> > 32bit) and found that
> >> > this line was missing:
> >> > QtGui.qApp.processEvents()
> >> >
> >> > Adding it sped the QT4Agg backend back to reasonable speeds--but it
> >> > still
> >> > seems a bit slow. Otherwise, I am using the excellent Python(x,y)
> >> > 2.1.14
> >> > release for my python distribution on this machine. Could this line
> be
> >> > added back?
> >>
> >> Unfortunately, no, that line can not be added back in. When that line
> >> is in place, the backend attempts to process queued events before it
> >> is finished processing the current event. It was leading to segfaults
> >> in some cases. processEvents should not be called in the middle of
> >> processing an event.
> >>
> >> I tested the responsiveness of panning and zooming with and without
> >> that call to processEvents, on Linux and windows and it looked fine.
> >> Maybe its an issue related to a specific Qt version on windows. Things
> >> looked fine for me with Qt-4.5/PyQt-4.5 on 64bit Vista.
> >>
> >> Darren
> >
> >
>
>
>
> --
> "In our description of nature, the purpose is not to disclose the real
> essence of the phenomena but only to track down, so far as it is
> possible, relations between the manifold aspects of our experience" -
> Niels Bohr
>
> "It is a bad habit of physicists to take their most successful
> abstractions to be real properties of our world." - N. David Mermin
>
> "Once we have granted that any physical theory is essentially only a
> model for the world of experience, we must renounce all hope of
> finding anything like the correct theory ... simply because the
> totality of experience is never accessible to us." - Hugh Everett III
>
"""
This demo demonstrates how to embed a matplotlib (mpl) plot
into a PyQt4 GUI application, including:
* Using the navigation toolbar
* Adding data to the plot
* Dynamically modifying the plot's properties
* Processing mpl events
* Saving the plot to a file from a menu
The main goal is to serve as a basis for developing rich PyQt GUI
applications featuring mpl plots (using the mpl OO API).
Eli Bendersky (eli...@gmail.com)
License: this code is in the public domain
Last modified: 19.01.2009
"""
import sys, os, random
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as
NavigationToolbar
from matplotlib.figure import Figure
class AppForm(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setWindowTitle('Demo: PyQt with matplotlib')
self.create_menu()
self.create_main_frame()
self.create_status_bar()
self.textbox.setText('1 2 3 4')
self.on_draw()
def save_plot(self):
file_choices = "PNG (*.png)|*.png"
path = unicode(QFileDialog.getSaveFileName(self,
'Save file', '',
file_choices))
if path:
self.canvas.print_figure(path, dpi=self.dpi)
self.statusBar().showMessage('Saved to %s' % path, 2000)
def on_about(self):
msg = """ A demo of using PyQt with matplotlib:
* Use the matplotlib navigation bar
* Add values to the text box and press Enter (or click "Draw")
* Show or hide the grid
* Drag the slider to modify the width of the bars
* Save the plot to a file using the File menu
* Click on a bar to receive an informative message
"""
QMessageBox.about(self, "About the demo", msg.strip())
def on_pick(self, event):
# The event received here is of the type
# matplotlib.backend_bases.PickEvent
#
# It carries lots of information, of which we're using
# only a small amount here.
#
box_points = event.artist.get_bbox().get_points()
msg = "You've clicked on a bar with coords:\n %s" % box_points
QMessageBox.information(self, "Click!", msg)
def on_draw(self):
""" Redraws the figure
"""
str = unicode(self.textbox.text())
self.data = map(int, str.split())
x = range(len(self.data))
# clear the axes and redraw the plot anew
#
self.axes.clear()
self.axes.grid(self.grid_cb.isChecked())
self.axes.bar(
left=x,
height=self.data,
width=self.slider.value() / 100.0,
align='center',
alpha=0.44,
picker=5)
self.canvas.draw()
def create_main_frame(self):
self.main_frame = QWidget()
# Create the mpl Figure and FigCanvas objects.
# 5x4 inches, 100 dots-per-inch
#
self.dpi = 100
self.fig = Figure((5.0, 4.0), dpi=self.dpi)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self.main_frame)
# Since we have only one plot, we can use add_axes
# instead of add_subplot, but then the subplot
# configuration tool in the navigation toolbar wouldn't
# work.
#
self.axes = self.fig.add_subplot(111)
# Bind the 'pick' event for clicking on one of the bars
#
self.canvas.mpl_connect('pick_event', self.on_pick)
# Create the navigation toolbar, tied to the canvas
#
self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)
# Other GUI controls
#
self.textbox = QLineEdit()
self.textbox.setMinimumWidth(200)
self.connect(self.textbox, SIGNAL('editingFinished ()'), self.on_draw)
self.draw_button = QPushButton("&Draw")
self.connect(self.draw_button, SIGNAL('clicked()'), self.on_draw)
self.grid_cb = QCheckBox("Show &Grid")
self.grid_cb.setChecked(False)
self.connect(self.grid_cb, SIGNAL('stateChanged(int)'), self.on_draw)
slider_label = QLabel('Bar width (%):')
self.slider = QSlider(Qt.Horizontal)
self.slider.setRange(1, 100)
self.slider.setValue(20)
self.slider.setTracking(True)
self.slider.setTickPosition(QSlider.TicksBothSides)
self.connect(self.slider, SIGNAL('valueChanged(int)'), self.on_draw)
#
# Layout with box sizers
#
hbox = QHBoxLayout()
for w in [ self.textbox, self.draw_button, self.grid_cb,
slider_label, self.slider]:
hbox.addWidget(w)
hbox.setAlignment(w, Qt.AlignVCenter)
vbox = QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
vbox.addLayout(hbox)
self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)
def create_status_bar(self):
self.status_text = QLabel("This is a demo")
self.statusBar().addWidget(self.status_text, 1)
def create_menu(self):
self.file_menu = self.menuBar().addMenu("&File")
load_file_action = self.create_action("&Save plot",
shortcut="Ctrl+S", slot=self.save_plot,
tip="Save the plot")
quit_action = self.create_action("&Quit", slot=self.close,
shortcut="Ctrl+Q", tip="Close the application")
self.add_actions(self.file_menu,
(load_file_action, None, quit_action))
self.help_menu = self.menuBar().addMenu("&Help")
about_action = self.create_action("&About",
shortcut='F1', slot=self.on_about,
tip='About the demo')
self.add_actions(self.help_menu, (about_action,))
def add_actions(self, target, actions):
for action in actions:
if action is None:
target.addSeparator()
else:
target.addAction(action)
def create_action( self, text, slot=None, shortcut=None,
icon=None, tip=None, checkable=False,
signal="triggered()"):
action = QAction(text, self)
if icon is not None:
action.setIcon(QIcon(":/%s.png" % icon))
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if slot is not None:
self.connect(action, SIGNAL(signal), slot)
if checkable:
action.setCheckable(True)
return action
def main():
app = QApplication(sys.argv)
form = AppForm()
form.show()
app.exec_()
if __name__ == "__main__":
main()
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel