有没有办法扭转热图中y轴的顺序 [英] Is there a way to reverse the order of the y axis in heatmap of plotly
本文介绍了有没有办法扭转热图中y轴的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有
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来打印热图?
But it prints the heatmap with the y axis from 18 to 7 is there a way to print it from 7 to 18?
推荐答案
您好,我尝试了提供的代码,但收到一条错误消息,说Y轴(小时)数不等于Z轴数(matrixDatos) ).因此,为了使代码正常工作,我将范围从7减小到16.
Hi I tried the code provided, I was getting an error saying that number of Y-axis (hours) does not equal the number of Z-axis (matrixDatos). So I reduced the range from 7 to 16 for the code to work.
我在布局对象中使用了 xaxis对象的自动调整范围" 参数,为了反转该轴,我们需要使用 反向" 参数.
I used the "autorange" parameter of the xaxis object in layout object, to reverse the axis we need to use "reversed" parameter.
原始代码(有问题)输出: 代码更改:
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)
代码更改输出:
我希望这是您所需要的.
I hope this is what you need.
参考文献:
这篇关于有没有办法扭转热图中y轴的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文