Jay Prakash Thakur
Jay Prakash Thakur

Reputation: 615

plot overlaps using matplotlib

I am learning matplotlib.

I am trying to plot two below plots in a single plot using matplotlib.

enter image description here

enter image description here

But it overlaps. enter image description here

Here is my code.

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

train_error = [0.26462888486225206, 0.26462383329393313, 0.2628674962680674, 0.2553700231555298, 0.17473717177688022, 0.14773444580059242, 0.1468299949185866, 0.1468235689407127, 0.1439370366766204]
test_error = [0.8438224756653776, 0.8442034650577578, 1.018608707726192, 4.853704454584892, 123.69312582226338, 798.4569874115062, 3205.5264038946007, 9972.587330411312, 10787335.618580218]

plt.plot(train_error)
plt.plot(test_error)
plt.show()

Where am i doing wrong ? Can anyone please guide / help ?

Upvotes: 0

Views: 41

Answers (1)

Apo
Apo

Reputation: 338

Use the subplot

Go check https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html

plt.subplot(1,2,1)
plt.plot(train_error)
plt.subplot(1,2,2)
plt.plot(test_error)

in plt.subplot(a,b,x) you have a,b that represents the number of (row and column) you want vertically and horizontally and x the index of the subplot selected counting from left to right and top to bottom.

Upvotes: 1

Related Questions