Data Visualization Using Seaborn Library In Python.

Salman Ibne Eunus
CodeX
Published in
3 min readFeb 4, 2022

Data Visualization is an important tool to gain better understanding and to get more knowledge about the data. It helps data scientists to communicate with non data science people by telling a unique story using data. It is a representation of data using charts, graphs or maps to comprehend and visualize trends and patterns in data.

In this blog, we will learn how to use the most prevalent data visualization library known as ‘seaborn’. Seaborn is a python data visualization library for which has an outstanding interface for drawing attractive and informative statistical graphs. It is built on top of matplotlib, which is another important data visualization library. Seaborn also works well with pandas data-frame while helping us to explore and derive meaningful insights from the data. The plotting function of seaborn can perform very well with dataframes and arrays with whole datasets and perform the necessary semantic mapping and statistical aggregation to produce informative plots.

Now we will see some examples of code using seaborn in python —

# Import seaborn
import seaborn as sns

# Apply the default theme
sns.set_theme()

# Load an example dataset
tips = sns.load_dataset("tips")

# Create a visualization
sns.relplot(
data=tips,
x="total_bill", y="tip", col="time",
hue="smoker", style="smoker", size="size",
)

In the example above, we need to import only seaborn library. It is imported with the short form ‘sns’ as a convention. It uses matplotlib underneath to draw the plots. This plot shows the relationship among five variables in the tips data-set using a single call of the seaborn function relplot(). The relplot() is able to visualize different types of statistical relationships. The code above also uses a function called load_dataset() to get access to a sample dataset quickly. We can also create much simpler data plots such as — histogram and kde plots using seaborn. Take a look at how to plot a histogram and kde(kernel density estimation) plot below —

penguins = sns.load_dataset("penguins")
sns.histplot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")
sns.kdeplot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")

Seaborn is a broad library with many functions which gives a much better statistical understanding of the data. In this tutorial, I have shown some simple and common examples to just introduce the library to the beginners.

To learn more about seaborn, you can visit the official documentation of seaborn library which has a number of tutorials with examples.

You can also learn other uncommon plots such as — Empirical Cumulative Distribution Function (ECDF) plot which represents the count of observations falling below each unique value in a dataset. In ECDF, each observation is visualized directly without using binning or smoothing parameters like in histogram or density plots.

To install seaborn you can also check the link below —

I hope this short introduction of seaborn library will help you to explore data to obtain useful insights about the data. See you next time!

--

--

Salman Ibne Eunus
CodeX
Writer for

Data Scientist|Robotics Engineer||AI Researcher| Bioinformatics