使用visdom动态绘制n条曲线

本次演示使用两种方式:replace和append

代码示例:
from visdom import Visdom
from  time import sleep


'''

以这三条曲线为例:
y = 80*x
y = x**2
y = -100*x-100

'''

viz = Visdom()
x = []
Yn =[]

opts1 = {
    "title": 'chart example1',
    "xlabel":'x',
    "ylabel":'y',
    "width":300,
    "height":200,
    "legend":['b','c','d']
}
opts2 = {
    "title": 'chart example2',
    "xlabel":'x',
    "ylabel":'y',
    "width":300,
    "height":200,
    "legend":['b','c','d']
}
for i in range(1000):
    x.append(i)
    Yn.append([i*80, i**2, -i*100-100])

    ##方式一,replace
    viz.line(X=x, Y=Yn, win='chart1', opts=opts1)

    ##方式二,append
    viz.line(X=[i], Y=[[i * 80, i ** 2, -i * 100 - 100]], win='chart2', update='append',
             opts=opts2)
    sleep(0.01)
效果图:

你可能感兴趣的:(使用visdom动态绘制n条曲线)