Charts reduce the complexity of the data and make it easier to understand for any user.

They are very powerful tools, and they have their audience.

It is ideal for data scientists.

A beginner’s guide to data visualization with Python and Seaborn

Many great libraries are available for Python to work with data likenumpy,pandas,matplotlib,tensorflow.

It’s free, every week, in your inbox.

Matplotlibis probably the most recognized plotting library out there, available for Python and other programming languages likeR.

Article image

It is its level of customization and operability that set it in the first place.

However, some actions or customizations can be hard to deal with when using it.

In this article, we will focus on how to work with Seaborn to create best-in-class plots.

Article image

What is Seaborn?

Seabornis a library for making statistical graphics in Python.

It builds on top ofmatplotliband integrates closely withpandas data structures.

Article image

Seaborn design allows you to explore and understand your data quickly.

It abstracts complexity while allowing you to design your plots to your requirements.

When installingseaborn, the library will install its dependencies, includingmatplotlib,pandas,numpy, andscipy.

Article image

Lets then install Seaborn, and of course, also the packagenotebookto get access to our data playground.

Additionally, we are going to import a few modules before we get started.

Building your first plots

Before we can start plotting anything, we need data.

Article image

The beauty ofseabornis that it works directly withpandasdataframes, making it super convenient.

Lets see how that works by loading a dataset that contains information about flights.

Creating a scatter plot in the Seaborn library is so simple and with just one line of code.

Article image

Sample scatter plot

Very easy, right?

The functionscatterplotexpects the dataset we want to plot and the columns representing thexandyaxis.

Line Plot

This plot draws a line that represents the revolution of continuous or categorical data.

Article image

It is a popular and known punch in of chart, and its super easy to produce.

Similarly to before, we use the functionlineplotwith the dataset and the columns representing thexandyaxis.Seabornwill do the rest.

Extending with matplotlib

Seaborn builds on top ofmatplotlib, extending its functionality and abstracting complexity.

Article image

With that said, it does not limit its capabilities.

Anyseabornchartcan be customized using functions from thematplotliblibrary.

Sample plot with sub-plots

Using thesubplotfunction, we can draw more than one chart on a single plot.

Article image

We are rendering aseabornchartin each subplot, mixingmatplotlibwithseabornfunctions.

In our case, we will use the dataset tips that you could download directly usingseaborn.

First, load the dataset.

Article image

Next, we can start plotting some charts.

Understanding tip percentages

Lets try first to understand the tip percentage distribution.

For that, we can usehistplotthat will generate a histogram chart.

Article image

This will force the chart to use different colors for each value oftimeand add a legend to it.

Understanding tip percentages per day plot

It looks like Friday is a good day to stay home.

For example, how do the day of the week and the table size impact the tip percentage?

Article image

I hope that you enjoyed this article as much as I enjoyed writing it.

Sign up for updates on everything related to programming, AI, and computer science in general.

Also tagged with

Article image

Article image

Article image