Skip to content

Instantly share code, notes, and snippets.

@rlabbe
Last active March 14, 2023 13:09
Show Gist options
  • Select an option

  • Save rlabbe/ea3444ef48641678d733 to your computer and use it in GitHub Desktop.

Select an option

Save rlabbe/ea3444ef48641678d733 to your computer and use it in GitHub Desktop.
Plot with matplotlib with real time updates without plt.pause
# draw the figure so the animations will work
import matplotlib.pyplot as plt
fig = plt.gcf()
fig.show()
fig.canvas.draw()
while True:
# compute something
plt.plot([1, 2, 3, 4, 5], [2, 1, 2, 1, 2]) # plot something
# update canvas immediately
plt.xlim([0, 10])
plt.ylim([0, 10])
plt.pause(0.01)
fig.canvas.draw()
@NISH1001

NISH1001 commented Nov 3, 2017

Copy link
Copy Markdown

Nice. Thanks.

@dmitry-kabanov

Copy link
Copy Markdown

Hmm, does not work for me.
I use Qt5 backend.

@vtonder

vtonder commented Mar 5, 2018

Copy link
Copy Markdown

This worked great for me, but I'm interested in plotting multiple figures. I tried creating new figures as follows but this didn't work:
Do you perhaps have any ideas?

fig = plt.gcf()
fig.show()
fig.canvas.draw()

fig1 = plt.gcf()
fig1.show()
fig1.canvas.draw()

while True:
# compute something
plt.plot([1], [2]) # plot something
fig.canvas.draw()

plt.plot(x,y)
fig1.canvas.draw()

Thanks

@QuentinWach

Copy link
Copy Markdown

@vtonder Did you find a solution?

@litepresence

Copy link
Copy Markdown

#plt.pause(0.01) # I ain't needed!!!

plt.pause is when you pull cursor coordinates and use zoom, save, home, etc. buttons. You disabled all those features.

also consider what your cpu's are doing with no plt.pause() vs 0.01 vs a full second of plot pause in that loop.

@endolith

endolith commented Dec 2, 2018

Copy link
Copy Markdown

Doesn't work for me :/

@pmteaofmay

Copy link
Copy Markdown

Doesn't work for me :/

@gouelp

gouelp commented Nov 22, 2019

Copy link
Copy Markdown

If it dosen't work for you try to add a style marker parameter like 'r+' for red cross, by default it can be invisible. For example to plot random numbers between 0 and 50.

x = random.randint(0,50)
y = random.randint(0,50)
plt.plot([x],[y],'r+')

@OrangoMango

Copy link
Copy Markdown

It does not work

@AbhisekSinghRao

Copy link
Copy Markdown

Guys I made an oscillscope code for live plot but now i want to make GUI of it using Pyqt5 but i am not getting how shall i do...do someone can help me out

@rlabbe

rlabbe commented Sep 9, 2021

Copy link
Copy Markdown
Author

This gist is not made for public consumption, I just occasionally make gists to remind me of something. I'm not supporting it, especially if the message is "it does not work".

@OrangoMango

Copy link
Copy Markdown

This gist is not made for public consumption, I just occasionally make gists to remind me of something. I'm not supporting it, especially if the message is "it does not work".

Ok, but maybe you can fix it. It has no sence to post something that does not work. (Im not the only one who can't let it work)

@rlabbe

rlabbe commented Sep 9, 2021

Copy link
Copy Markdown
Author

It makes sense because it works for me (and some others), and this is a convenient place to store such things. I don't need somebody else to do my thinking for me, thank you.

I have no idea what setups people have, what versions, what OS, what backend, etc. And I certainly can't help when the entire message is "it does not work". Lazy efforts get zero response.

But again, I don't really care, this is for me only.

@OrangoMango

Copy link
Copy Markdown

As you want, I wanted just to inform you

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