I created the normal distribution, but how do I put it into a subplot? Output shown below:
import matplotlib.pyplot as plt
import seaborn as sb
import pandas as pd
import numpy as np
import os
fig, axis = plt.subplots(3)
# Subplot 1
mu, sigma = 0, 0.1
s = np.random.normal(mu, sigma, 1000)
abs(sigma - np.std(s, ddof=1))
count, bins, ignored = plt.hist(s, 30, density=True)
plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * np.exp(- (bins - mu)**2 / (2 * sigma**2)), linewidth=2, color='r')
axis[0].plot(s)
plt.show()
You will create a figure of 3 subplots that are arranged in a column as shown below:
Subplot 1:
- Create a variable y that contains 100 random numbers distributed in a standard normal distribution.
- Plot the histogram of y (set bins=50).
Subplot 2:
- Create an array of 3 ranges of numbers from -1 to 1, in increments of 0.01.
- Create an array as the cosine function of A. (Hint: np.cos)
- Plot B vs A.
Subplot 3:
- Create an array of 7 numbers: 1, -0.5, -1, 0.
- Plot the array.
Format the subplots as shown below:
Subplot 1:
- Title: Normal Distribution
- X-axis label: Values
- Y-axis label: Frequency
Subplot 2:
- Title: Cosine Function
- X-axis label: A
- Y-axis label: B
Subplot 3:
- Title: Array Plot
- X-axis label: Index
- Y-axis label: Values