常规热图有效,但图形工厂热图在Plotly中失败

问题描述 投票:2回答:1

数据

fin_list

[[None, 9.1, 8.8, 8.7, 8.8, 9.1, 9.2, 9.2, 9.0, 9.6],
 [None, 8.8, 8.5, 8.8, 8.8, 8.8, 9.1, 8.9, 8.8, 9.7],
 [None, 8.8, 8.6, 8.9, 9.6, 9.0, 8.8, 8.7, 9.0, 9.9],
 [None, 9.1, 9.7, 8.9, 8.8, 8.7, 9.7, 9.1, 9.7, 9.6],
 [None, 8.5, 8.5, 8.5, 8.7, 8.6, 8.0, 9.0, 9.9, 9.5],
 [None, 8.5, 9.4, 8.7, 9.1, 9.7, 8.4, 8.6, 8.4, 9.9],
 [None, 8.6, 8.9, 9.2, 9.8, 8.8, 9.1, 9.4, None, None],
 [None, 7.6, 7.9, 7.5, 5.5, 6.0, 4.1, None, None, None]]

sorted(series ['episodes'])] >>

[1, 2, 3, 4, 5, 6, 7, 8]

y_episodes

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

使用Graph_objects的热图代码

import plotly.graph_objects as go

fig = go.Figure(data=go.Heatmap(
                   x=y_episodes,
                   y=sorted(series['episodes']),
                   z=fin_list,
                   colorscale = 'OrRd',
                   hoverongaps = False))

输出-enter image description here

[当我尝试使用绘图factory figure重新创建热图时>]

import plotly.figure_factory as ff

fig = ff.create_annotated_heatmap( 
                   x=sorted(series['episodes']),
                   y=y_episodes,
                   z=fin_list,
                   colorscale = 'OrRd')

错误:PlotlyError:糟糕,您提供的x列表与z矩阵的宽度不匹配

但是我的坐标轴在上图中是正确的。

print(len(sorted(series['episodes']))) #x_axis = 8
print(len(y_episodes)) #y_axis = 11
print(len(fin_list)) #z_axis = 8

我的最终目标是对热图进行注释,如果有一种解决方法,可以在使用graph_objects(而不是图形工厂)的代码中添加注释,请告诉我。

数据fin_list [[无,9.1,8.8,8.7,8.8,9.1,9.2,9.2,9.0,9.6],[无,8.8,8.5,8.8,8.8,8.8,9.1,8.9,8.8,9.7],[无,8.8,8.6,8.9,9.6,9.0,8.8,8.7,9.0,9.9],[无,9.1,9.7,8 ....

python python-3.x plotly heatmap
1个回答
0
投票

使用numpy.nan代替,其类型为float。您可以使用嵌套列表理解来替换fin_list中的值:

list_nans=[[np.nan if y is None else y for y in x] for x in fin_list]
© www.soinside.com 2019 - 2024. All rights reserved.