0% found this document useful (0 votes)
31 views9 pages

Seaborn Basic Plots

Uploaded by

Dinesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views9 pages

Seaborn Basic Plots

Uploaded by

Dinesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

seaborn

#seaborn
Table of Contents
About 1

Chapter 1: Getting started with seaborn 2

Remarks 2

Examples 2

Installation or Setup 2

Chapter 2: Barplot 3

Examples 3

Barplot with Gradient 3

Chapter 3: Correlation plot 5

Introduction 5

Examples 5

Basic correlation plot 5

Credits 7
About
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: seaborn

It is an unofficial and free seaborn ebook created for educational purposes. All the content is
extracted from Stack Overflow Documentation, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official seaborn.

The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.

Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to [email protected]

https://riptutorial.com/ 1
Chapter 1: Getting started with seaborn
Remarks
This section provides an overview of what seaborn is, and why a developer might want to use it.

It should also mention any large subjects within seaborn, and link out to the related topics. Since
the Documentation for seaborn is new, you may need to create initial versions of those related
topics.

Examples
Installation or Setup

Detailed instructions on getting seaborn set up or installed.

Read Getting started with seaborn online: https://riptutorial.com/seaborn/topic/5307/getting-


started-with-seaborn

https://riptutorial.com/ 2
Chapter 2: Barplot
Examples
Barplot with Gradient

Imagine you have a simple dataframe to plot on a barplot like:

df = pd.DataFrame({'a':[1,2,3,4,5], 'b':[10,5,2,4,5]})

using seaborn:

sns.barplot(df['a'], df['b'], palette='Blues_d')

you can obtain something like:

then you can also play with the palette option and colormap adding a gradient according to some
data like:

https://riptutorial.com/ 3
sns.barplot(df['a'], df['b'], palette=cm.Blues(df['b']*10)

obtaining:

Read Barplot online: https://riptutorial.com/seaborn/topic/6090/barplot

https://riptutorial.com/ 4
Chapter 3: Correlation plot
Introduction
A correlation plot can be regarded as a subcategory of heatmaps. An out-of-the box seaborn
heatmap shows the correlation between two variables twice. A correlation plot should handle
duplicated values by masking parts of the map, and / or let the masked part show values instead
of colors. A bar chart should also be included.

Examples
Basic correlation plot

A basic but illustrative heatmap showing correlations between a number of variables.

import pandas as pd
import seaborn as sns
import numpy as np

# Sample dataframe with date index and five variables


np.random.seed(123)
df = pd.DataFrame(np.random.uniform(-0.25,0.25,size=(5, 5)),
columns = ['Var A','Var B','Var C', 'Var D', 'Var E'])
df['Dates'] = pd.date_range(start = None, end = pd.datetime.today().strftime('%Y-%m-%d'),
periods=5).tolist()
df = df.set_index(['Dates'])

# Compute correlations
corr = df.corr()

# Exclude duplicate correlations by masking uper right values


mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set background color / chart style


sns.set_style(style = 'white')

# Set up matplotlib figure


f, ax = plt.subplots(figsize=(11, 9))

# Add diverging colormap


cmap = sns.diverging_palette(10, 250, as_cmap=True)

# Draw correlation plot


sns.heatmap(corr, mask=mask, cmap=cmap,
square=True,
linewidths=.5, cbar_kws={"shrink": .5}, ax=ax)

https://riptutorial.com/ 5
Possible improvements:

1. Remove redundant labels on y-axis (Var A) and x-axis (Var E)


2. Add correlations (values) either in lower left or upper right part of the map

Read Correlation plot online: https://riptutorial.com/seaborn/topic/10634/correlation-plot

https://riptutorial.com/ 6
Credits
S.
Chapters Contributors
No

Getting started with


1 Community
seaborn

2 Barplot Fabio Lamanna

3 Correlation plot vestland

https://riptutorial.com/ 7

You might also like