Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib figure opened but matplotlib window "not responding"

in windows I try to run this code. Serial works fine and compass value converted to float matplotlib figure opened but matplotlib window "not responding" not draws anything.

import serial
import numpy
import matplotlib.pyplot as plt
ser = serial.Serial('COM8',9600,timeout=2)

ciz,=plt.plot([],[])

def update_ciz(ciz,newdata):
     ciz.set_xdata(numpy.append(ciz.get_xdata(),newdata))
     ciz.set_ydata(numpy.append(ciz.get_ydata(),newdata))
     plt.draw()
while (True):
     line = ser.readline()
     k=line.split(":")
     temperature=k[0]
     pressure= k[1]
     attitude=k[2]
     realAttitude=k[3]
     compass=float(k[4])
     gx=k[5]
     gy=k[6]
     gz=k[7]
     ax=k[8]
     ay=k[9]
     az=k[10]
     acond=k[11]
     update_ciz(ciz,compass)
like image 601
acs Avatar asked Nov 20 '25 16:11

acs


1 Answers

In matplotlib you need to use "plt.show()" to display the plot. Since you are using "plt.draw()" to update the plot, you probably also want to use the interactive mode.

Try including this after your "ciz,=plt.plot([],[])" command:

plt.ion()
plt.show()
like image 75
DanHickstein Avatar answered Nov 22 '25 06:11

DanHickstein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!