gpt4 book ai didi

python-3.x - 有没有办法在 plotly 的热图中反转 y 轴的顺序

转载 作者:行者123 更新时间:2023-12-03 18:31:01 24 4
gpt4 key购买 nike

所以我有

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。

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

原始代码(有问题提供)输出:
plotly heatmap annotated
代码变更:

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)

代码更改输出:
plotly annotated heatmap reversed

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

引用:
  • plotly layout xaxis reference
  • 关于python-3.x - 有没有办法在 plotly 的热图中反转 y 轴的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45641213/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com