seaborn.heatmap
- seaborn.heatmap(data, *, vmin=None, vmax=None, cmap=None, center=None, robust=False, annot=None, fmt='.2g', annot_kws=None, linewidths=, , , , , , , , , ,
Plot rectangular data as a color-encoded matrix.
This is an Axes-level function and will draw the heatmap into the
currently-active Axes if none is provided to the ax argument. Part of
this Axes space will be taken and used to plot a colormap, unless cbar
is False or a separate Axes is provided to cbar_ax.
2D dataset that can be coerced into an ndarray. If a Pandas DataFrame is provided, the index/column information will be used to label the columns and rows.
Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments.
The mapping from data values to color space. If not provided, the
default will depend on whether center is set.
The value at which to center the colormap when plotting divergent data.
Using this parameter will change the default cmap if none is
specified.
If True and vmin or vmax are absent, the colormap range is
computed with robust quantiles instead of the extreme values.
If True, write the data value in each cell. If an array-like with the
same shape as data, then use this to annotate the heatmap instead
of the data. Note that DataFrames will match on position, not index.
String formatting code to use when adding annotations.
Keyword arguments for matplotlib.axes.Axes.text() when annot
is True.
Width of the lines that will divide each cell.
Color of the lines that will divide each cell.
Whether to draw a colorbar.
Keyword arguments for matplotlib.figure.Figure.colorbar().
Axes in which to draw the colorbar, otherwise take space from the main Axes.
If True, set the Axes aspect to “equal” so each cell will be square-shaped.
If True, plot the column names of the dataframe. If False, don’t plot the column names. If list-like, plot these alternate labels as the xticklabels. If an integer, use the column names but plot only every n label. If “auto”, try to densely plot non-overlapping labels.
If passed, data will not be shown in cells where mask is True.
Cells with missing values are automatically masked.
Axes in which to draw the plot, otherwise use the currently-active Axes.
All other keyword arguments are passed to
matplotlib.axes.Axes.pcolormesh().
Axes object with the heatmap.
Pass a DataFrame to plot with indices as row/column labels:
glue = sns.load_dataset("glue").pivot(index="Model", columns="Task", values="Score")
sns.heatmap(glue)
Use annot to represent the cell values with text:
sns.heatmap(glue, annot=True)
Control the annotations with a formatting string:
sns.heatmap(glue, annot=True, fmt=".1f")
Use a separate dataframe for the annotations:
sns.heatmap(glue, annot=glue.rank(axis="columns"))
Add lines between cells:
sns.heatmap(glue, annot=True, linewidth=.5)
Select a different colormap by name:
sns.heatmap(glue, cmap="crest")
Or pass a colormap object:
sns.heatmap(glue, cmap=sns.cubehelix_palette(as_cmap=True))
Set the colormap norm (data values corresponding to minimum and maximum points):
sns.heatmap(glue, vmin=50, vmax=100)
Use methods on the matplotlib.axes.Axes object to tweak the plot:
ax = sns.heatmap(glue, annot=True)
ax.set(xlabel="", ylabel="")
ax.xaxis.tick_top()