How to plot multiple functions on the same figure, in Matplotlib? How to plot multiple functions on the same figure, in Matplotlib? python python

How to plot multiple functions on the same figure, in Matplotlib?


To plot multiple graphs on the same figure you will have to do:

from numpy import *import mathimport matplotlib.pyplot as pltt = linspace(0, 2*math.pi, 400)a = sin(t)b = cos(t)c = a + bplt.plot(t, a, 'r') # plotting t, a separately plt.plot(t, b, 'b') # plotting t, b separately plt.plot(t, c, 'g') # plotting t, c separately plt.show()

enter image description here


Perhaps a more pythonic way of doing so.

from numpy import *import mathimport matplotlib.pyplot as pltt = linspace(0,2*math.pi,400)a = sin(t)b = cos(t)c = a + bplt.plot(t, a, t, b, t, c)plt.show()

enter image description here


Just use the function plot as follows

figure()...plot(t, a)plot(t, b)plot(t, c)