Answers for "multiple plots in the same figure matplotlib"

2

matplotlib multiple plots

fig = plt.figure()

# total_rows, total_columns, subplot_index(1st, 2nd, etc..)
plt.subplot(2, 2, 1)
plt.plot(x, y)

plt.subplot(2, 2, 2)
plt.plot(x, y)

plt.subplot(2, 2, 3)
plt.plot(x, y)

plt.subplot(2, 2, 4)
plt.plot(x, y)
Posted by: Guest on January-16-2021
1

how to plot 2 graphs in same plot in matplotlib

x1 = [1, 2, 3]
Data for the first line

y1 = [4, 5, 6]

x2 = [1, 3, 5]
Data for the second line

y2 = [6, 5, 4]

plt.plot(x1, y1)
plt.plot(x2, y2)

plt.legend(["Dataset 1", "Dataset 2"])
Create a legend for the graph
Posted by: Guest on June-21-2021

Code answers related to "multiple plots in the same figure matplotlib"

Python Answers by Framework

Browse Popular Code Answers by Language