A bar chart or bar plot represents categorical data with rectangular bars. The heights or lengths of the bars are proportional to the values they represent. For example, let’s look into the titanic dataset. The dataset contains various information, such as age, embark town of the passengers, whether they survived, class of the titanic ship in which they travelled, etc. Let’s say we want to know the average age of passengers travelling in each class of the titanic ship. We can do so using the following Python code:
import seaborn from matplotlib import pyplot df = seaborn.load_dataset("titanic") seaborn.barplot(data=df, x="pclass", y="age") pyplot.savefig("seaborn-bar-chart.png") pyplot.close()
The resulting bar plot will show the average age of passengers travelling in each class of titanic. The bar plot will look like the following:
0 Comments