Plotly 简明教程
Plotly - Heatmap
热力图(或热图)是数据的图形化表示,其中数据集中包含的各个值表示为颜色。热图的主要目的是更好地可视化数据集中的位置/事件的数量,并帮助将查看者定向到数据可视化中最重要的地方。
A heat map (or heatmap) is a graphical representation of data where the individual values contained in a matrix are represented as colors. The primary purpose of Heat Maps is to better visualize the volume of locations/events within a dataset and assist in directing viewers towards areas on data visualizations that matter most.
由于热图依赖于颜色来传达值,因此它们最常用于显示数字值的概括视图。热图在吸引注意力时极其通用且高效,正因如此,它们在分析社区中变得越来越受欢迎。
Because of their reliance on color to communicate values, Heat Maps are perhaps most commonly used to display a more generalized view of numeric values. Heat Maps are extremely versatile and efficient in drawing attention to trends, and it’s for these reasons they have become increasingly popular within the analytics community.
热图本质上是不言自明的。阴影越深,数量越大(值越高,分散越紧密,依此类推)。Plotly 的 graph_objects 模块包含 Heatmap() 函数。它需要 x、 y 和 z 属性。它们的值可以是列表、numpy 数组或 Pandas 数据框。
Heat Maps are innately self-explanatory. The darker the shade, the greater the quantity (the higher the value, the tighter the dispersion, etc.). Plotly’s graph_objects module contains Heatmap() function. It needs x, y and z attributes. Their value can be a list, numpy array or Pandas dataframe.
在以下示例中,我们有一个 2D 列表或数组,其中定义了需要着色的数据(不同农民每年收获的吨/年)。然后,我们还需要两个农民姓名和他们耕种的蔬菜名称列表。
In the following example, we have a 2D list or array which defines the data (harvest by different farmers in tons/year) to color code. We then also need two lists of names of farmers and vegetables cultivated by them.
vegetables = [
"cucumber",
"tomato",
"lettuce",
"asparagus",
"potato",
"wheat",
"barley"
]
farmers = [
"Farmer Joe",
"Upland Bros.",
"Smith Gardening",
"Agrifun",
"Organiculture",
"BioGoods Ltd.",
"Cornylee Corp."
]
harvest = np.array(
[
[0.8, 2.4, 2.5, 3.9, 0.0, 4.0, 0.0],
[2.4, 0.0, 4.0, 1.0, 2.7, 0.0, 0.0],
[1.1, 2.4, 0.8, 4.3, 1.9, 4.4, 0.0],
[0.6, 0.0, 0.3, 0.0, 3.1, 0.0, 0.0],
[0.7, 1.7, 0.6, 2.6, 2.2, 6.2, 0.0],
[1.3, 1.2, 0.0, 0.0, 0.0, 3.2, 5.1],
[0.1, 2.0, 0.0, 1.4, 0.0, 1.9, 6.3]
]
)
trace = go.Heatmap(
x = vegetables,
y = farmers,
z = harvest,
type = 'heatmap',
colorscale = 'Viridis'
)
data = [trace]
fig = go.Figure(data = data)
iplot(fig)
上面提到的代码的输出如下 −
The output of the above mentioned code is given as follows −
