1import pandas as pd
2import seaborn as sns
3import matplotlib.pyplot as plt
4#Seaborn again offers a neat tool to visualize pairwise correlation coefficients.
5#The heatmap takes the DataFrame with the correlation coefficients as inputs,
6#and visualizes each value on a color scale that reflects the range of relevant. values.
7#The parameter annot equals True ensures that the values of the correlation
8#coefficients are displayed as well
9sns.heatmap(df.corr(), annot =True )
10sns.set(rc = {'figure.figsize':(8,8)})#<--responsible for changing the size of a seaborn plot
11plt.show()
1import seaborn as sns
2%matplotlib inline
3
4# calculate the correlation matrix
5corr = auto_df.corr()
6
7# plot the heatmap
8sns.heatmap(corr,
9 xticklabels=corr.columns,
10 yticklabels=corr.columns)
11
1import pandas as pd
2import seaborn as sns
3
4sns.heatmap(dataframe.corr(), annot=True) # annot is optional
1# Basic syntax:
2sns.heatmap(df, xticklabels=x_labels, yticklabels=y_labels)
3
4# Example usage:
5import seaborn as sns
6flight = sns.load_dataset('flights') # Load flights datset from GitHub
7 # seaborn repository
8
9# Reshape flights dataeset to create seaborn heatmap
10flights_df = flight.pivot('month', 'year', 'passengers')
11
12x_labels = [1,2,3,4,5,6,7,8,9,10,11,12] # Labels for x-axis
13y_labels = [11,22,33,44,55,66,77,88,99,101,111,121] # Labels for y-axis
14
15# Create seaborn heatmap with required labels
16sns.heatmap(flights_df, xticklabels=x_labels, yticklabels=y_labels)