Is there a way to reverse the order of the y axis in heatmap of plotly

不问归期 提交于 2019-12-22 11:33:52

问题


So I have

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')

But it prints the heatmap with the y axis from 18 to 7 is there a way to print it from 7 to 18?


回答1:


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.

I used the "autorange" parameter of the xaxis object in layout object, to reverse the axis we need to use "reversed" parameter.

Original Code (provided in question) Output: 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:

I hope this is what you need.

References:

  1. plotly layout xaxis reference


来源:https://stackoverflow.com/questions/45641213/is-there-a-way-to-reverse-the-order-of-the-y-axis-in-heatmap-of-plotly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!