Home  >  Q&A  >  body text

Python 画图:在同一张图上画两次,怎样执行?

如题。
Matlab中,执行一次plot后,用语句hold on
然后再plot,两次画图即在一张图上。

在Python中,matplotlib.pyplot或者更多程序包,怎样实现?
多次plot,在同一张图上?

PHP中文网PHP中文网2741 days ago3170

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 14:55:06

    matplotlib is almost the same as Matlab, and does not require a hold on statement. For example

    import matplotlib.pyplot as plt
    
    x = range(10)
    y1 = [elem*2 for elem in x]
    plt.plot(x, y1)
    
    y2 = [elem**2 for elem in x]
    plt.plot(x, y2, 'r--')
    
    plt.show()
    

    reply
    0
  • Cancelreply