Updating a plot doesn't clear old plots, if event trigger came from another figure? · Issue #10183 · matplotlib/matplotlib · GitHub
Skip to content

Updating a plot doesn't clear old plots, if event trigger came from another figure? #10183

Description

@clsmt

Bug report

Bug summary

I am updating a line plot. There is an event trigger that starts this updating. If the trigger came from the figure that contains the plot, everything is fine. However, if the trigger came from another figure, then weird results happen: the line that's been updated appears to leave its trace uncleared.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

def onclick(event):

    for ii in np.linspace(0., np.pi, 100):
        y1 = y * np.sin(ii)
        line1.set_ydata(y1)
        ax.draw_artist(line1)
        line2.set_ydata(-y1)
        ax2.draw_artist(line2)
        ax2.set_ylim(y1.min(), y1.max())
        fig.canvas.update()
        plt.pause(0.1)


x = np.linspace(0., 2*np.pi, 100)
y = np.sin(x)

fig = plt.figure()
ax = fig.add_subplot(1, 2, 1)
line1 = ax.plot(x, y)[0]

ax2 = fig.add_subplot(1, 2, 2)
line2 = ax2.plot(x, y)[0]


fig2 = plt.figure()

cid = fig2.canvas.mpl_connect('button_press_event', onclick)
# cid = fig.canvas.mpl_connect('button_press_event', onclick)

plt.show()

Actual outcome

image

Expected outcome

Not the many curves saw in the above figure, just one curve being updated in each cycle. In the code snippet, if use

cid = fig.canvas.mpl_connect('button_press_event', onclick)

then it works as intended.

Also note, if you resize the plot, or save it as figure, then all the residue curves will be gone.

Matplotlib version

  • Operating system: windows
  • Matplotlib version: 2.0.0
  • Matplotlib backend (print(matplotlib.get_backend())): Qt4Agg
  • Python version: 2.7
  • Jupyter version (if applicable):
  • Other libraries:

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

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions