Multiple plots in one figure in Python

This is very simple to do:

import matplotlib.pyplot as plt

plt.plot(<X AXIS VALUES HERE>, <Y AXIS VALUES HERE>, 'line type', label="label here")
plt.plot(<X AXIS VALUES HERE>, <Y AXIS VALUES HERE>, 'line type', label="label here")
plt.legend(loc="best")
plt.show()

You can keep adding plt.plot as many times as you like. As for line type, you need to first specify the color. So for blue, it’s b. And for a normal line it’s -. An example would be:

plt.plot(total_lengths, sort_times_heap, 'b-', label="Heap")

Leave a Comment