Windows are not shown with Tk + interactive mode, from matplotlib 3.4 · Issue #19935 · matplotlib/matplotlib · GitHub
Skip to content

Windows are not shown with Tk + interactive mode, from matplotlib 3.4 #19935

Description

@kngwyu

Bug report

Bug summary

The behavior of Tk backend in interactive mode has changed. My code depends on the old behavior and does not work with matplotlib 3.4.

Code for reproduction

import time

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt


def test_heatmap_draw():
    mpl.use("TkAgg")
    plt.ion()

    DATA_SHAPE = 10, 10
    fig = plt.figure()
    ax = fig.add_subplot()
    img = ax.imshow(np.zeros(DATA_SHAPE), vmin=-1, vmax=1)

    for _ in range(10):
        img.set_data(np.random.uniform(-1, 1, DATA_SHAPE))
        fig.canvas.draw()
        time.sleep(0.1)


if __name__ == "__main__":
    test_heatmap_draw()

Actual outcome
No windows are shown with matplotlib >= 3.4.
I guess that #17789 is the trigger. Inserting self._master.update_idletasks worked, like:

class FigureCanvasTkAgg(FigureCanvasAgg, FigureCanvasTk):
    def draw(self):
        super().draw()
        self.blit()
        self._master.update_idletasks()

Expected outcome
The heatmap is interactively updated with matplotlib 3.3.4.

  • Is this change intended? Then I want to know a proper way to write this kind of app. I know that plt.pause(0.1) works, but actually don't want to pause in my actual use case.
  • If this is not intended, how could I fix backends in a reasonable way?

BTW, thank you for encouraging me on twitter.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions