seaborn create horizontal bar graph

Solutions on MaxInterview for seaborn create horizontal bar graph by the best coders in the world

showing results for - "seaborn create horizontal bar graph"
Erica
19 Sep 2017
1import seaborn as sns
2import matplotlib.pyplot as plt
3sns.set_theme(style="whitegrid")
4
5# Initialize the matplotlib figure
6f, ax = plt.subplots(figsize=(6, 15))
7
8# Load the example car crash dataset
9crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False)
10
11# Plot the total crashes
12sns.set_color_codes("pastel")
13sns.barplot(x="total", y="abbrev", data=crashes,
14            label="Total", color="b")
15
16# Plot the crashes where alcohol was involved
17sns.set_color_codes("muted")
18sns.barplot(x="alcohol", y="abbrev", data=crashes,
19            label="Alcohol-involved", color="b")
20
21# Add a legend and informative axis label
22ax.legend(ncol=2, loc="lower right", frameon=True)
23ax.set(xlim=(0, 24), ylabel="",
24       xlabel="Automobile collisions per billion miles")
25sns.despine(left=True, bottom=True)
26