Python Data Science 简明教程

Python - Heat Maps

热图包含值,代表要绘制的每个值的相同颜色的各种阴影。通常,图表中的深色阴影表示比浅色阴影更高的值。对于非常不同的值,也可使用完全不同的颜色。

A heatmap contains values representing various shades of the same colour for each value to be plotted. Usually the darker shades of the chart represent higher values than the lighter shade. For a very different value a completely different colour can also be used.

以下示例是一个二维值的图,它被映射到图表中的索引和列。

The below example is a two-dimensional plot of values which are mapped to the indices and columns of the chart.

from pandas import DataFrame
import matplotlib.pyplot as plt

data=[{2,3,4,1},{6,3,5,2},{6,3,5,4},{3,7,5,4},{2,8,1,5}]
Index= ['I1', 'I2','I3','I4','I5']
Cols = ['C1', 'C2', 'C3','C4']
df = DataFrame(data, index=Index, columns=Cols)

plt.pcolor(df)
plt.show()

它的 output 如下所示 −

Its output is as follows −

heatmap