osx - Matplotlib plt.ion does not show a figure, Python3 on Mac using Pycharm -


for each loop there new value of y being calculated. , want update figure each new y each loop.

i used following codes. used python 3.6.2 anaconda. , use pycharm editing.

import numpy np import matplotlib.pyplot plt  import time   class dynamicupdate():     def __init__(self):         self.x_min = 0         self.x_max = 100         self.fig, self.ax = plt.subplots()         self.lines, = self.ax.plot([], [], '-ob')         self.lines_avg, = self.ax.plot([], [], '-or')         self.ax.set_autoscaley_on(true)         self.ax.grid()         print(type(self.lines), type(self.lines_avg))      def on_running(self, xdata, ydata, ydata_mean):         self.lines.set_xdata(xdata)         self.lines.set_ydata(ydata)         self.lines_avg.set_xdata(xdata)         self.lines_avg.set_ydata(ydata_mean)         title = 'average = %.2f' % ydata_mean[-1]         plt.title(title)         self.ax.relim()         self.ax.autoscale_view()         self.fig.canvas.draw()         self.fig.canvas.flush_events()   def main():     plt.ion()     update_plot = dynamicupdate()     xs = list()     ys = list()     ys_mean = list()     k in np.arange(4):         time.sleep(1)         x = k         y = np.sin(100*np.pi*x*5e-4)         xs.append(x)         ys.append(y)         ys_mean.append(np.mean(ys))         update_plot.on_running(xs, ys, ys_mean)      plt.ioff()     plt.show()   if __name__ == '__main__':     main() 

it works on windows 10 laptop, on macbook pro, no figure shows following message

<class 'matplotlib.lines.line2d'> <class 'matplotlib.lines.line2d'> 

could please me making work on mac? thanks.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -