0

Basically just what I said in the title. I have an absurdly simple example of this happening for me:


print("test 1")
plt.pause(2)
print("test 2")

fig, ax = plt.subplots()

print("test 1")
plt.pause(2)
print("test 2")

When I run this, it pauses for the first test print, but does not pause afterwards. This showed up in a more complicated setup, but it happens even in this sort of super simple situation.

Edit: to be clear I need plt.pause to work because I need to be able to get figures to update; I'm not just trying to pause execution. My code here doesn't show any plot updating because the issue isn't in that part of the code (debugging and manually pausing execution causes plots to update normally) and I wanted to find the simplest case where pause doesn't work. Sorry if that was unclear.

Tarnarmour
  • 115
  • 1
  • 6
  • Why not use the common ``time.sleep()`` instead of ``plt.pause()``? – Karina Jul 22 '21 at 09:25
  • @Tarnarmour What do you expect `plt.pause` to do when you call it before creating any figure and axes? – Guimoute Jan 22 '23 at 18:20
  • Well I'd expect the pause function to pause the program, which is exactly what it does. My point is that for some reason after creating a figure, the pause function STOPS working. – Tarnarmour Feb 15 '23 at 22:55

1 Answers1

0

I don't know your context or purpose of using plt.pause(), but using time.sleep() surely works in your case.

import time

print("test 1")
time.sleep(2)
print("test 2")

fig, ax = plt.subplots()

print("test 1")
time.sleep(2)
print("test 2")

the command plt.pause() is more likely needed if you want to have pause time for displaying something IN your plt figure, not a simple print(something) command

Karina
  • 1,252
  • 2
  • 5
  • 16
  • That is exactly why I need pause. I reduced this down the simplest example but the real problem here is that I have a program that is not displaying changes to a graph. – Tarnarmour Aug 07 '21 at 01:18
  • Don't understand. So the problem is not in the code you provided in your question? Then why not edit your question? – Karina Aug 07 '21 at 14:35
  • The problem is that pause is not pausing after subplots is called, which is happening in this example code. That is an issue because pause is needed to make matplotlib update figures, but the simplest reproducible case for pause not working is exactly what I showed above. – Tarnarmour Aug 08 '21 at 16:11
  • Oh okay, I kind of understand what you want. I could recommend you to read this: https://matplotlib.org/stable/gallery/event_handling/timers.html I tried it myself but somehow it doesn't work for me. Couldn't help further. Sorry! – Karina Aug 08 '21 at 19:29