Home > Software design >  How to have two histograms but not stacked?
How to have two histograms but not stacked?

Time:12-01

I would like to have the two histograms I have created but they should be next to each other and not on top of each other. Can you help me?

Code:

import pandas as pd 
members = pd.read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-09-22/members.csv")
import matplotlib.pyplot as plt
import seaborn as sns

sns.set(palette="Reds_r")
plt.figure(figsize=(15,10))
members_injury_height = members["injury_height_metres"]
members_death_height = members["death_height_metres"]
members_injury_height.hist(density=True,alpha = 0.5,bins = 20) 
members_death_height.hist(density=True, alpha = 0.2 ,bins = 20) 
plt.xlabel("Hauteurs")
plt.ylabel("% de membres morts/blessés")
plt.title("Répartition des hauteurs auxquelles des membres se sont blessés ou sont morts")
fond = plt.gca()
fond.set_facecolor('whitesmoke')
plt.gca().legend(('blessés', 'morts'))

CodePudding user response:

You can combine the two data rows in one single plot by adding the data rows in a list inside your plt.hist function.

Check out the enter image description here

  • Related