Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Let's Cope with Axes | Plot Customization
First Dive into seaborn Visualization

book
Let's Cope with Axes

Setting label names:

To set label names, we need to set a plot variable and use:

python
# g is the plot variable.
g.set(xlabel = 'x_name', ylabel = 'y_name')

X(y)ticks rotation:

To rotate labels, we need to use:

python
# n is the angle
plt.xticks(rotation = n)
plt.yticks(rotation = n)
Task

Swipe to start coding

  1. Import seaborn with sns alias.
  2. Import matplotlib.pyplot with plt alias.
  3. Import pandas with pd alias.
  4. Set label names 'Population'(Oy axis) & 'Years(2012-2022)'(Ox axis).
  5. Rotate labels along the Ox axis by 45 degrees.
  6. Show the plot.

Solution

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/lineplothue.csv')

g = sns.lineplot(x = 'year', y = 'population', hue = 'season', data = df)

g.set(ylabel = 'Population', xlabel = 'Years(2012-2022)')

plt.xticks(rotation = 45)

plt.show()

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 3
# Import libraries needed
___
___
___

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/lineplothue.csv')

# Setting the variable
g = sns.lineplot(x = 'year', y = 'population', hue = 'season', data = df)

# Set label names
___.___(ylabel = '___', ___ = '___')

# Rotate
___.___(rotation = ___)

# Show the plot
___

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt