how to plot heat map with python seaborn package

created at 07-01-2021 views: 42


A common application scenario of the heat map is to draw the correlation coefficient heat map, and the data prepares a correlation coefficient matrix.

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['figure.dpi'] = 80 # Graphic resolution
pd.options.display.notebook_repr_html=False # Table display

Correlation coefficient matrix

np.random.seed(1) # Random seed
          a         b         c         d         e         f
a  1.000000  0.297407 -0.610065 -0.908297 -0.997893 -0.991160
b  0.297407  1.000000 -0.937936  0.129262 -0.234835 -0.421449
c -0.610065 -0.937936  1.000000  0.222660  0.557370  0.709796
d -0.908297  0.129262  0.222660  1.000000  0.933525  0.844767
e -0.997893 -0.234835  0.557370  0.933525  1.000000  0.980463
f -0.991160 -0.421449  0.709796  0.844767  0.980463  1.000000


Call the heatmap method to draw a heat map.



Adjust the color palette

Set the vmin and vmax parameters to adjust the lower limit and upper limit of the palette.

# Set the upper and lower limits of the palette

Adjust the color palette

Set cmap parameters, you can modify the palette style.


Set cmap parameters

Hide legend

Set the parameter cbar=False to hide the legend.


Hide legend

Display value

Set the parameter annot=True to display the specific value on the heat map, and set the fmt parameter to modify the style of the value display.


Display value

created at:07-01-2021
edited at: 07-01-2021: