1

I'm having a serious issue with pyplot not displaying my figure until the end of my code. The code below is a simplest example I can think of, and recreates the problem for me. When plt.plot(range(10)) is called an unresponsive and empty figure window open, but at the end of the code (after the sleep) the graph is displayed. The time is a placeholder for a while(True) loop that is supposed to read from a seriel device and update the graph, which is impossible as I cannot force the graph to draw before the end of code.

# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
import time

plt.plot(range(10))
#plt.show()
plt.draw()
# while loop for computations, simulated by a sleep command
time.sleep(2)

I am at my wits end. Using backend Qt4Agg. Operating system is windows 7, and am using python 2.7.

Jeppe Friberg
  • 21
  • 1
  • 4
  • You need to call plt.show() http://stackoverflow.com/questions/23141452/difference-between-plt-draw-and-plt-show-in-matplotlib – Rubbal Oct 13 '16 at 11:17
  • 1
    @Rubbal; does that work for you? In my case, `plt.show()` or `plt.show(block=False)` still doesn't show the image until after the `time.sleep()`. – Bart Oct 13 '16 at 12:23
  • It works for me. I'm on python 2.7, OSX. – Rubbal Oct 13 '16 at 12:42

1 Answers1

0

https://stackoverflow.com/a/24272092/2555211

This solution worked well for me. I expect the canvas.flush_events() is what was missing.

Community
  • 1
  • 1
Jeppe Friberg
  • 21
  • 1
  • 4