有没有办法反转plotly热图中y轴的顺序

2024-04-15

所以我有

hours = [x for x in range(7,18)]
columns = [1, 2, 3, 4, 5]

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



    table = ff.create_table(matrixDatos)

    fig = ff.create_annotated_heatmap(matrixDatos, x=columns, y=hours, colorscale='Viridis')

但它打印 y 轴从 18 到 7 的热图,有没有办法打印从 7 到 18 的热图?


您好,我尝试了提供的代码,但收到一条错误消息,指出 Y 轴数量(小时)不等于 Z 轴数量(matrixDatos)。因此,我将范围从 7 减少到 16,以使代码能够正常工作。

我用的是“自动量程”的参数x轴对象 in 布局对象,要反转我们需要使用的轴“逆转”范围。

Original Code (provided in question) Output: plotly heatmap annotated Code Change:

hours = [x for x in range(7,17)]
columns = [1, 2, 3, 4, 5]

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



table = ff.create_table(matrixDatos)

fig = ff.create_annotated_heatmap(matrixDatos, x=columns, y=hours, colorscale='Viridis')
fig['layout']['yaxis']['autorange'] = "reversed"
iplot(fig)

Code Change Output: plotly annotated heatmap reversed

我希望这就是您所需要的。

参考:

  1. 绘图布局 xaxis 参考 https://plot.ly/python/reference/#layout-yaxis-autorange
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有没有办法反转plotly热图中y轴的顺序 的相关文章

随机推荐