GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PYTHON CHARTS
  • matplotlib
  • seaborn
  • plotly
  • pandas
  • colors
  • COLORS
  • COLOR PALETTES
  • R CODER
  • R CHARTS
  • Contact
  • Español

This view

  • Original page
  • New address

GeezerVison is showing python-charts.com — Heat map in seaborn with the heatmap function

Search for a graph

HOME CORRELATION HEATMAP SEABORN

Heat map in seaborn with the heatmap function

Heatmap in seaborn with heatmap

The heatmap function allows creating heat maps or correlation plots in Python with seaborn. You can pass a 2D data set or a pandas dataframe. In case you provide a pandas data frame the row and column names will be used to label the plot axes.

import numpy as np
import seaborn as sns

# Data simulation
np.random.seed(1)
data = np.random.rand(10, 10)

sns.heatmap(data)

Heat map in seaborn with the heatmap function

Squared tiles

Note that depending on the number of rows and columns and the size of the plot the tiles of the heat map could be non-square. If you want to fix the aspect ratio of the tiles set the argument square to True.

import numpy as np
import seaborn as sns

# Data simulation
np.random.seed(1)
data = np.random.rand(10, 10)

sns.heatmap(data, square = True)

Heat map in Python with squared cells

Border

You can also add a border for the tiles setting the width of the lines with linewidths, which defaults to 0. The default color will be white, but you can override it with linecolor.

import numpy as np
import seaborn as sns

# Data simulation
np.random.seed(1)
data = np.random.rand(10, 10)

sns.heatmap(data,
            linewidths = 0.75, 
            linecolor = "white") # Default color

Heat map with borders in seaborn

Annotations

In addition, it is possible to add the values for each cell with annot = True. If you need to change the size or other styling of the texts you can pass a dictionary to annot_kws, as in the example below.

import numpy as np
import seaborn as sns

# Data simulation
np.random.seed(1)
data = np.random.rand(10, 10)

sns.heatmap(data,
            annot = True,
            annot_kws = {'size': 6}) # Additional arguments

Text annotations size of a heat map made with seaborn

Color bar

Note that you can remove the color bar (the legend) if desired setting cbar = False, customize it passing a dictionary to cbar_kws or change the lower and upper limits of the bar with vmin and vmax, respectively.

import numpy as np
import seaborn as sns

# Data simulation
np.random.seed(1)
data = np.random.rand(10, 10)

sns.heatmap(data,
            cbar = False)

Remove the color bar of the Python heat map

Remove the axis labels

Setting the xticklabels and yticklabels arguments to False the labels for the X and Y axis will be deleted, respectively.

import numpy as np
import seaborn as sns

# Data simulation
np.random.seed(1)
data = np.random.rand(10, 10)

sns.heatmap(data,
            xticklabels = False, yticklabels = False)

Remove the axis labels of the heatmap in seaborn

Color customization

The colors of a heat map can be customized in two ways: you can create a diverging color palette setting a center value with center or changing the color palette with cmap, as shown in the following examples.

Heat map in seaborn with a diverging color palette

Diverging color palette

import numpy as np
import seaborn as sns

# Data simulation
np.random.seed(1)
data = np.random.rand(10, 10)

sns.heatmap(data,
            center = 0.5)

Change the color palette of the heatmap in seaborn

Change the color palette

import numpy as np
import seaborn as sns

# Data simulation
np.random.seed(1)
data = np.random.rand(10, 10)

sns.heatmap(data,
            cmap = "Blues")
R CODER website
Fundamentals of Data Visualization

Fundamentals of Data Visualization

A Primer on Making Informative and Compelling Figures

Buy on Amazon
Data visualization

Data visualization

A practical introduction

Buy on Amazon

See also

Scatter plot in pandas

Scatter plot in pandas

Histograms in plotly

Histograms in plotly

2D histogram in matplotlib

2D histogram in matplotlib

Scatter plot in plotly

Scatter plot in plotly

Scatter plot by group in seaborn

Scatter plot by group in seaborn

Connected scatter plot in matplotlib

Connected scatter plot in matplotlib

Heat map on a map (spatial heat map) in plotly

Heat map on a map (spatial heat map) in plotly

Scatter plot with marginal histograms in seaborn

Scatter plot with marginal histograms in seaborn

Heatmap clustering in seaborn with clustermap

Heatmap clustering in seaborn with clustermap

Scatter plot in matplotlib

Scatter plot in matplotlib

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.