Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyplot plot freezes (not responding)

I am struggling with pyplot from the matlpotlib library. The figure freezes already when I try to create the plot:

plt.figure()
plt.ion()
ax1 = plt.subplot(211) #Here it freezes
plt.title('test', fontsize=8)
plt.xlim(-1700, 1700)
plt.ylabel('x-axis')
plt.xlabel('y-axis')
plt.grid()
plt.show()
...do something else

I have only worked with Pyqt plots, but this time I would like to solve my Problem without multithreading since I do not care if the plot stops my code for a short moment. The problem is, the script does not stop but continues to run and does not wait until the figure is completely created. (time.sleep() does not help). Is there a solution without threads?

Cheers, James

Ps.: If I add a breakpoint after the code and run in debug mode, there is no Problem (obviously).

like image 734
James Trüeb Avatar asked May 30 '17 12:05

James Trüeb


1 Answers

Is this one working as you want it?

import matplotlib.pyplot as plt

plt.figure()
plt.ion()
ax1 = plt.subplot(211) #Here it freezes
plt.title('test', fontsize=8)
plt.xlim(-1700, 1700)
plt.ylabel('x-axis')
plt.xlabel('y-axis')
plt.grid()
plt.draw() # draw the plot
plt.pause(5) # show it for 5 seconds
print("Hallo") # continue doing other stuff
like image 150
ImportanceOfBeingErnest Avatar answered Oct 04 '22 11:10

ImportanceOfBeingErnest