Plotly教程

Plotly 热图

热图(或热图)是数据的图形表示,其中包含在矩阵中的各个值以颜色表示。热图的主要目的是更好地可视化数据集中的位置/事件数量,并帮助将查看者引导至数据可视化中最重要的区域。
因为他们对colo的依赖r 为了传达值,热图可能最常用于显示更通用的数值视图。热图在引起对趋势的关注方面极为通用且有效,正因为如此,它们在分析社区中越来越受欢迎。
热图本质上是不言自明的。阴影越深,数量越大(数值越高,分散越紧密等)。 Plotly 的 graph_objects 模块包含 Heatmap() 函数。它需要 x、 yz 属性。它们的值可以是列表、numpy 数组或 Pandas 数据框。
在下面的示例中,我们有一个二维列表或数组,用于将数据(不同农民的收成吨/年)定义为颜色代码。然后我们还需要两个农民和他们种植的蔬菜的名称列表。
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)
上述代码的输出如下-
热图
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4