# How to do subplot

## Overview

When we make machine learning model and check how accurate the predictions are, we frequently plot those.Plotting some graphs at the same time is very useful to compare outcomes. By matplotlib, those can be done.

## Code

```
import matplotlib.pyplot as plt
import numpy as np
import math
x = np.arange(0, 100, 0.1)
y_sin = np.sin(x)
y_cos = np.cos(x)
plt.subplot(121)
plt.plot(x, y_sin)
plt.subplot(122)
plt.plot(x, y_cos)
plt.show()
```

subplot(121) means that the plot area has 1 row, 2 columns and the plot just after written by plt.plot() is the first plot.

The plot is like this.

```
plt.subplot(211)
plt.plot(x, y_sin)
plt.subplot(212)
plt.plot(x, y_cos)
plt.show()
```

The plot is like this.

## No comments:

## Post a Comment