seaborn

The seaborn logo

The seaborn logo

Learning outcomes

At the end of this sessions, learners …

  • have practiced using the documentation of favorite HPC cluster

  • understand what seaborn is

  • understand why seaborn is important

  • have created a plot with seaborn

  • (optional) have created a plot with seaborn from a pandas table

What is seaborn?

seaborn allows you to create figures:

import seaborn as sns
y = [0, 1, 4, 9, 16]
sns.lineplot(x = range(len(y)), y = y).figure.show()

Which shows:

A minimal  plot

Why seaborn is important

seaborn is one of the most popular Python plotting libraries. It can be used to create publication-quality figures and the seaborn plot gallery shows that most plot types are present.

Exercises

Exercise 1: a minimal seaborn program

Use the documentation of the HPC cluster you work on.

In that documentation, find the software module to load the seaborn Python package.

In a terminal (on your HPC cluster), load the software module to use seaborn.

On your HPC cluster, create a script called seaborn_exercise_1.py with the following code:

import seaborn
print(seaborn.__version__)

Run the script.

What do you see?

Even though the code shows nothing directly useful, why is this a useful exercise anyways?

Exercise 2: a minimal plot

On your HPC cluster, create a script called seaborn_exercise_2.py, with the following content:

import seaborn as sns
y = [0, 1, 4, 9, 16]
sns.lineplot(x = range(len(y)), y = y).figure.savefig("seaborn_exercise_2.png")

Run the script.

Check that the figure is created.

 exercise 2

(optional) Exercise 3: displaying a pandas table

In this exercise, we will again use the ‘diamonds’ dataset (as a comma-separated file), click to download: a dataset about diamonds.

This dataset contains information about more than fifty thousand diamonds. Two such features are the weight (in carats) and the price (in USD). Here we want to use an image to display the relationship between these two.

On your HPC cluster, create a script called seaborn_exercise_3.py. In that script:

  • Use pandas to read the dataset

  • Use seaborn to create a scatter plot from that data. Put the diamond weight on the x-axis and the diamond price on the y-axis. Use the seaborn documentation, a search engine or an AI chatbot for the answer.

  • save the plot as seaborn_exercise_3.png Use the matplotlib documentation, a search engine or an AI chatbot for the answer.

(optional) Exercise 4: making the plot pretty

Use the seaborn documentation to improve the plot, for example:

  • Add a title

  • Add titles to the axes

  • Add a linear trendline

  • Whatever you like