Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cannot use threading with Mac OSX Backend #5251

Copy link
Copy link
Closed
@nils-werner

Description

@nils-werner
Issue body actions

The following does not work on Mac OSX:

from __future__ import division

import threading
import time
import sys
import numpy as np
import matplotlib
matplotlib.use('MacOSX')

import matplotlib.pyplot as plt


class async_worker(threading.Thread):
    def __init__(self, fig, axis):
        threading.Thread.__init__(self)
        self.fig = fig
        self.axis = axis

    def run(self):
        i = 0
        while True:
            print "Run thread %d" % i
            sys.stdout.flush()
            i += 1
            time.sleep(0.1)


def main():
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.plot(np.random.rand(251, 1))

    async_worker(fig, ax).start()
    plt.show()


if __name__ == "__main__":
    main()

I expect to see "Run thread" repeated every 0.1 seconds, no matter if I interact with the plot or not. Instead I only see it repeat when I click and drag around in the MPL figure.

When switching to matplotlib.use('TkAgg'), the second thread runs as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.