Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Bug]: animation.FuncAnimation not working without plt.show(block=True) #24588

Open
@jamesbraza

Description

@jamesbraza

Bug summary

I am findingmatplotlib.animation.FuncAnimation only updates whenplt.show(block=True). If this is the case, I think it should at least be documented inits docs.

Neither of the following work:

  • plt.show(block=False) (main thread) andplt.pause (main thread)
  • plt.show(block=False) (main thread) andfig.canvas.draw() andfig.canvas.flush_events() (data generation thread)

Code for reproduction

importrandomimporttimefromcollections.abcimportIterablefromthreadingimportThreadimportmatplotlibimportmatplotlib.animationasanimationimportmatplotlib.artistimportmatplotlib.pyplotaspltmatplotlib.use("QtAgg")# NOTE: need interactive backend to show plotfig,ax=plt.subplots()ax.set_xlim(0,1)ax.set_ylim(0,1)lines:list[matplotlib.artist.Artist]= []defadd_line(num_points:int=10,sleep_time:float=0.2)->None:x_data,y_data= [], []    (line,)=ax.plot(x_data,y_data)lines.append(line)defadd_random_datapoint()->None:x_data.append(random.random())y_data.append(random.random())line.set_data(x_data,y_data)# NOTE: I am letting FuncAnimation handle drawing and flushing eventsfor_inrange(num_points):add_random_datapoint()time.sleep(sleep_time)defanimate(frame:int,*fargs)->Iterable[matplotlib.artist.Artist]:yieldfromlinesani=animation.FuncAnimation(fig,animate,interval=100)plt.pause(0.1)# Begin seeding datathread=Thread(target=add_line,daemon=False)thread.start()# plt.show(block=True)  # Works fineplt.show(block=False)# Doesn't workthread.join()_=0

Actual outcome

The data doesn't show up on the plot until the full data generation has taken place, regardless of addingplt.pause or canvas flushing calls.

Expected outcome

I expectanimation.FuncAnimation(fig, animate, interval=100) to display data every 100-ms, even ifplt.show(block=False).

Additional information

No response

Operating system

macOS Monterey version 12.6

Matplotlib Version

3.6.2

Matplotlib Backend

QtAgg

Python version

3.10.8

Jupyter version

n/a

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp