python - x-axis not updating in for loop -


the general question have this: can use plt.axis in loop such if condition isn't met old axis limits replaced new ones? have tried below having x-axis set 0-10 first 10 iterations, set x-axis xmin xmax thereafter plot not updating properly. there missing?

from time import sleep import pylab pl import matplotlib.pyplot plt  temperature = [] x = list() y = list() y1 = list() dt_tol = .5  plt.ion() fig = plt.figure(1)  ax1 = fig.add_subplot(211) temp_plot = plt.scatter([],[])       plt.ylabel('temperature (c)')  ax2 = fig.add_subplot(212) delta_temp_plot = plt.scatter([],[],zorder = 2) plt.axhspan(-dt_tol, dt_tol, color='#87cefa', alpha=1, zorder = 1) plt.ylabel('dt') plt.xlabel('time (s)')  plt.draw()  # read loop in range(60):     tempc = #for simplicity, can real t later     temperature.append(tempc)     dt = temperature[i]-temperature[i-1]      x.append(i)     y.append(temperature[i])     y1.append(dt)      if len(x)>10:         del x[0]         del y[0]         del y1[0]      xmin = min(x)     xmax = max(x)         if -dt_tol<dt<dt_tol:         print "temperature:","%.3f"% temperature[i],"         " "dt:", "%.3f"% dt, "         " "steady state"         sleep(1)     else:         print "temperature:","%.3f"% temperature[i],"         " "dt:", "%.3f"% dt         sleep(1)      #replace old points new points     temp_plot.set_offsets(zip(x,y))     delta_temp_plot.set_offsets(zip(x,y1))      if len(x)<=10:         ax1.axis([0,10,0,80])         ax2.axis([0,10,0,80])     else:         ax1.axis([xmin,xmax,0,80])         ax2.axis([xmin,xmax,-4,4])      fig.canvas.draw() 


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -