【问题标题】:Matplotlib updating axisMatplotlib 更新轴
【发布时间】:2012-01-23 18:01:12
【问题描述】:

我正在寻找允许我在脚本运行时更新轴的方法,但是我找不到它。例如:

import matplotlib.pyplot as plt

x = (1,2)
y = (1,2)

plt.plot(x,y, 'r-')
plt.show()

#here during run of program I want to clear axis with help of plt.cla() and update it 
#new one

# x = (2,4)
# y = (2,4)
#plt.plot(x,y, 'b-')

【问题讨论】:

    标签: numpy matplotlib ipython


    【解决方案1】:

    要获得您想要的功能,您可能需要将 matplotlib 设置为交互模式:

    plt.ion()
    

    然后调用draw进行更新。例如:

    import numpy
    import time
    x = (1,2)
    y = (1,2)
    plt.ion()
    plt.plot(x,y, 'r-')
    plt.draw()
    
    for i in range(100):
       print i
       time.sleep(1)
       plt.cla()
       y = (numpy.random.normal(), numpy.random.normal())
       plt.plot(x,y, 'r-')
       plt.draw()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 2013-01-15
      相关资源
      最近更新 更多