Python Matplotlib multiple plots - How to draw graphs in the same plane

You can draw two graphs in the same place at once by Python Matplotlib. Before plotting, importing NumPy and Matplotlib in Python.

import numpy
from matplotlib import pyplot

x = numpy.arange(-5, 5, 0.1)
y = x * x
z = x + 2

pyplot.plot(x, y, x, z)

x ranges from -5 to 5 and the step is 0.1. y and z represents quadratic curve an line respectively.

pyplot module in matplotlib has plot method plotting (x, y) and (x, z). To draw 2 graphs, the arguments of plot is x, y, x, z, not x, y, z.


Powered by Markdown