2

The problem I'm facing is with the slowness in redrawing a small circle on the plot.

I'm currently doing the equivalent of the interactive class listed in Joe Kington's anwer here -matplotlib: update position of patches (or: set_xy for circles)

import matplotlib.pyplot as plt
from matplotlib.patches import Circle
import time

class InteractiveCircle(object):
    def __init__(self):
        self.fig, self.ax = plt.subplots()
        self.ax.axis('equal')

        self.circ = Circle((0.5, 0.5), 0.1)
        self.ax.add_artist(self.circ)
        self.ax.set_title('Click to move the circle')

        self.fig.canvas.mpl_connect('button_press_event', self.on_click)

    def on_click(self, event):
        if event.inaxes is None:
            return
        self.circ.center = event.xdata, event.ydata
        start_time = time.time()
        self.fig.canvas.draw()
        print "%f" %(time.time() - start_time)

    def show(self):
        plt.show()


InteractiveCircle().show()

This takes >800ms to redraw a small circle in the graph!!

I tried self.ax.draw_artist(self.circ) from http://matplotlib.1069221.n5.nabble.com/blit-animation-with-patches-td25634.html. This takes <1ms but doesn't redraw the circle :)

I'm very surprised that updating a tiny part of the graph is so slow. I'm looking for a solution that is <1ms.

Any suggestions?

EDIT: Removing reference to tkinter as slowness is reproducible with a matplotlib only example

EDIT: OS - RHEL 5.8

matplotlib --verbose-helpful output
version 1.2.0
platform is linux2
backend TkAgg version 8.6

EDIT: I'm using X-windows over SSH

Community
  • 1
  • 1
user1827356
  • 6,764
  • 2
  • 21
  • 30
  • 1
    You should not use `pyplot` if you are embedding the graph, the main loop of your TK application fights with the main loop in `pyplot` – tacaswell Jul 26 '13 at 20:24
  • and I can not re-produce this, I get order 0.012923 using your code (but run through ipython and with the qt4 backend) – tacaswell Jul 26 '13 at 20:27
  • @tcaswell I'm following this example - http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html. I'm not using pyplot. I'm using TkAgg as my backend. However, I'm running this over x windows. Does matplotlib have efficiency issues with this? Tkinter seems to run fine and is very responsive – user1827356 Jul 26 '13 at 21:03
  • The code you posted includes `import matplotlib.pyplot as plt` and you use `plt.subplots`, so I am having trouble squaring what you say and what your code is doing ;) – tacaswell Jul 26 '13 at 21:14
  • Updated question to remove reference to tkinter. I'm observing 800ms slowness in updating using the TkAgg and Qt4Agg backends over X-windows – user1827356 Jul 26 '13 at 21:25
  • what OS? And you should look into `blit`ing – tacaswell Jul 26 '13 at 21:57
  • Added version info. I did try blit, went down to 300ms – user1827356 Jul 26 '13 at 22:17
  • this a local machine or remote machine? – tacaswell Jul 26 '13 at 22:18
  • Remote. Why does local machine info matter? – user1827356 Jul 26 '13 at 22:41
  • I missed that you are sshing to this server. You should make that clear in the question. I suspect network latency is the real problem here. – tacaswell Jul 26 '13 at 22:44
  • Possible, but I'm doing more complex updates to a bunch of other (non matplotlib) tk canvas objects. Visually they seem to update without hiccups. The update processing <1ms as well. It's only updates to the matplotlib objects that are suffering. When I isolated them to a matplotlib only example this slowness persisted – user1827356 Jul 26 '13 at 22:50
  • My network rtt is ~15ms if that helps – user1827356 Jul 26 '13 at 22:51
  • How is your gui updating faster than your rtt? I don't know enough to have anything else useful to say on this. Maybe try the matplotlib mailing list. – tacaswell Jul 26 '13 at 23:03

0 Answers0