I'm using matplotlib to create a density and blox plot but when I run my code, I get one graph with two plots overlapping each other. How can I restructure my code to output two separate individual graphs?
link to graph image: https://ibb.co/6bCK9MZ
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
def make_t_distribution(sample_size, mean, sd):
t_sample = stats.t.rvs(sample_size - 1, mean, sd, sample_size) # Random t-distribution sample
sample_mean = np.mean(t_sample) # sample mean
sample_std = np.std(t_sample) # sample standard deviation
t_dist = stats.t(df = sample_size - 1, loc = sample_mean, scale = sample_std) # make a t-distribution based on the sample
x_axis = np.linspace(t_dist.ppf(0.0001), t_dist.ppf(0.9999), 500) # Generate an x-axis based on t-quantile values
return t_dist, x_axis
def make_prob_plot():
ax = plt.axes()
tdist1, x1=make_t_distribution(10,0,2)
tdist2, x2=make_t_distribution(100,0,2)
tdist3, x3=make_t_distribution(1000,0,2)
tdist4, x4=make_t_distribution(10000,0,2)
tdist5, x5=make_t_distribution(500,0,2)
# density plot
plt.xlim(-7.5,7.5)
y1=ax.plot(x1,tdist1.pdf(x1), '-', label="$df=9$")
y2=ax.plot(x2,tdist2.pdf(x2), ':', label="$df=99$")
y3=ax.plot(x3,tdist3.pdf(x3), '--' ,label="$df=999$")
y4=ax.plot(x4,tdist4.pdf(x4), '-.', label="$df=9999$")
y5=ax.plot(x5,tdist5.pdf(x5), '.', label="$Normal$")
plt.xlabel("Value")
plt.ylabel("Density")
plt.title("PDF Distribution Comparison $N(\mu=0$, $\sigma=2$)")
plt.legend()
# boxplot
dist1 = np.random.normal(0,2,10)
dist2 = np.random.normal(0,2,100)
dist3 = np.random.normal(0,2,1000)
dist4 = np.random.normal(0,2,10000)
distributions = (dist1, dist2, dist3, dist4)
plt.boxplot(distributions, labels = ("df=9","df=99","df=999","df=9999"));
plt.boxplot(distributions, widths= .7);
green_diamond = dict(markerfacecolor='g', marker='D')
plt.boxplot(distributions, flierprops=green_diamond);
return plt
make_prob_plot()