MatPlotLib's ion() and draw() not working

后端 未结 4 1626
我在风中等你
我在风中等你 2021-01-18 08:00

I am trying to plot figures in real time using a for loop. I have the following simple code:

import matplotlib.pyplot as plt

plt.ion()
plt.figure()
for i in         


        
4条回答
  •  -上瘾入骨i
    2021-01-18 08:30

    Hey I was having the same problem, I checked other questions and my issue was solved when I plugged a pause into my solution. Here's some example code that worked for me.

    import matplotlib.pyplot as plt
    import numpy as np
    plt.ion()
    x = np.arange(0, 4*np.pi, 0.1)
    y = [np.sin(i) for i in x]
    plt.plot(x, y, 'g-', linewidth=1.5, markersize=4)
    plt.pause(0.0001)         
    plt.plot(x, [i**2 for i in y], 'g-', linewidth=1.5, markersize=4)
    plt.pause(0.0001)
    plt.plot(x, [i**2*i+0.25 for i in y], 'r-', linewidth=1.5, markersize=4) 
    plt.pause(0.0001)
    

    The solution was posted here: Matplotlib ion() and subprocesses

提交回复
热议问题