Matplotlib Box Plot Histogram Error

Hello,
I am trying to generate both a box plot and a histogram to visualize my data; however, I am getting some error that I am not quite sure what to make of. Below is my code and a picture of the figure it generates. Please let me know if you can spot the issue!

# Side-by-Side plot data spred analysis:

sns.boxplot(data = titanic, x ='Survived', y = 'Fare' )

#create the histograms:

plt.hist(deseased_mean, color="red", label="Died", normed=True, alpha=0.5)
plt.hist(survior_mean, color="green", label="Survived", normed=True, alpha=0.5)
plt.legend()
plt.show()

Above you can see that the histograms are not even generating; although the legend shows up…

I think you have to run plt.clf() to clear the boxplot in order to see the histogram.

https://www.geeksforgeeks.org/difference-between-cla-clf-and-close-methods-in-matplotlib/

1 Like

Thank you for the link!

1 Like