FAQ: Learn Seaborn Introduction - Review

This community-built FAQ covers the “Review” exercise from the lesson “Learn Seaborn Introduction”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

Data Visualization in Python

FAQs on the exercise Review

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

While playing around with the review code, I tried to Barplot the responses by age category and hue by gender.

import codecademylib3_seaborn
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns

df = pd.read_csv("survey.csv")


sns.barplot(data=df, x='Age Range', y='Response', hue="Gender")

plt.show()

The result does what it’s supposed to to, however, the age groups on the x-axis start with the oldest and become younger with each tick, which is rather unintuitive. If I wanted to have this displayed inversely, what would be the proper way to proceed?

Thanks in advance! :slight_smile:

1 Like

We can use order parameter to set a specific order for the bars.

sortedlabels = sorted(df['Age Range'].unique())
sns.barplot(data=df, x='Age Range', y='Response', hue="Gender", order=sortedlabels)
1 Like