{"action":"created","issue":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/5675","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/5675/labels{/name}","comments_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/5675/comments","events_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/5675/events","html_url":"https://github.com/matplotlib/matplotlib/issues/5675","id":122087996,"number":5675,"title":"plt.pause() with threading is extremely slow for MacOSX backend","user":{"login":"danijar","id":2111293,"avatar_url":"https://avatars.githubusercontent.com/u/2111293?v=3","gravatar_id":"","url":"https://api.github.com/users/danijar","html_url":"https://github.com/danijar","followers_url":"https://api.github.com/users/danijar/followers","following_url":"https://api.github.com/users/danijar/following{/other_user}","gists_url":"https://api.github.com/users/danijar/gists{/gist_id}","starred_url":"https://api.github.com/users/danijar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danijar/subscriptions","organizations_url":"https://api.github.com/users/danijar/orgs","repos_url":"https://api.github.com/users/danijar/repos","events_url":"https://api.github.com/users/danijar/events{/privacy}","received_events_url":"https://api.github.com/users/danijar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-14T17:15:15Z","updated_at":"2015-12-15T14:06:45Z","closed_at":null,"body":"Here is a minimal example where a worker produces a sequence that's plotted every second by the main thread. Between the draw calls, the main thread pauses for 0.001s to update the GUI and sleeps for 1s. This takes 10 seconds. When pausing for 1s and sleeping for 0.001s instead, I would expect this to run in about the same time. However, it takes 70 seconds.\r\n\r\n```python\r\nimport random\r\nimport time\r\nimport threading\r\nimport matplotlib.pyplot as plt\r\n\r\n\r\nclass Plot:\r\n\r\n    def __init__(self):\r\n        plt.ion()\r\n        plt.show()\r\n        self.xdata = []\r\n        self.ydata = []\r\n        self.running = None\r\n        self.axis = plt.figure().add_subplot(111)\r\n        self.line, = self.axis.plot([])\r\n\r\n    def start(self):\r\n        self.running = True\r\n        threading.Thread(target=self.worker).start()\r\n        while self.running:\r\n            self.axis.set_xlim(0, len(self.xdata))\r\n            self.axis.set_ylim(0, max(self.ydata))\r\n            self.line.set_data(self.xdata, self.ydata)\r\n            plt.draw()\r\n            plt.pause(0.001)\r\n            time.sleep(1)\r\n\r\n    def worker(self):\r\n        for _ in range(100):\r\n            self.xdata.append(len(self.xdata))\r\n            self.ydata.append(random.random())\r\n            time.sleep(0.1)\r\n        self.running = False\r\n\r\n\r\nif __name__ == '__main__':\r\n    start = time.time()\r\n    Plot().start()\r\n    print(time.time() - start)\r\n```\r\n\r\nProfiling revealed that by far the most time is spent in `start_event_loop` of `_macosx.FigureCanvas`.\r\n\r\nPossibly related: https://github.com/matplotlib/matplotlib/issues/5251"},"comment":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/comments/164774794","html_url":"https://github.com/matplotlib/matplotlib/issues/5675#issuecomment-164774794","issue_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/5675","id":164774794,"user":{"login":"koogle","id":6087389,"avatar_url":"https://avatars.githubusercontent.com/u/6087389?v=3","gravatar_id":"","url":"https://api.github.com/users/koogle","html_url":"https://github.com/koogle","followers_url":"https://api.github.com/users/koogle/followers","following_url":"https://api.github.com/users/koogle/following{/other_user}","gists_url":"https://api.github.com/users/koogle/gists{/gist_id}","starred_url":"https://api.github.com/users/koogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koogle/subscriptions","organizations_url":"https://api.github.com/users/koogle/orgs","repos_url":"https://api.github.com/users/koogle/repos","events_url":"https://api.github.com/users/koogle/events{/privacy}","received_events_url":"https://api.github.com/users/koogle/received_events","type":"User","site_admin":false},"created_at":"2015-12-15T14:06:44Z","updated_at":"2015-12-15T14:06:44Z","body":"Thanks for the explanation. I tried the updated script but the window does not get redrawn at all.\r\nWhich version of matplotlib are you referring to? (I am using 1.5.0)"}}