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.

3
  • You need to call plt.show() stackoverflow.com/questions/23141452/… Commented Oct 13, 2016 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(). Commented Oct 13, 2016 at 12:23
  • It works for me. I'm on python 2.7, OSX. Commented Oct 13, 2016 at 12:42

1 Answer 1

0

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

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.