Create a barplot with the barplot() method. The barplot plot below shows the survivors of the titanic crash based on category. You’ll see these bar charts go down as the ship was sinking :)
The palette parameter defines the colors to be used, currently ‘hls’ is used but any palette is possible.
The barplot can be a horizontal plot with the method barplot(). In the example below two bar plots are overlapping, showing the percentage as part of total crashes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set_context('paper')
crashes = sns.load_dataset('car_crashes').sort_values('total', ascending = False) f, ax = plt.subplots(figsize = (6,15)) sns.set_color_codes('pastel') sns.barplot(x = 'total', y = 'abbrev', data = crashes, label = 'Total', color = 'b', edgecolor = 'w') sns.set_color_codes('muted') sns.barplot(x = 'alcohol', y = 'abbrev', data = crashes, label = 'Alcohol-involved', color = 'b', edgecolor = 'w') ax.legend(ncol = 2, loc = 'lower right') sns.despine(left = True, bottom = True) plt.show()
barplot tips
The barplot tips plot below uses the tips data set. It shows the number of tips received based on gender. Its uses the blues palette, which has variations of the color blue.
1 2 3 4 5 6 7 8 9 10 11 12 13
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set_context('paper')