【问题标题】:Plotly imshow reversing y labels reverses the imagePlotly imshow reversing y labels reverses the image
【发布时间】:2022-12-01 12:49:25
【问题描述】:

I'd like to visualize a 20x20 matrix, where top left point is (-10, 9) and lower right point is (10, -9). So the x is increasing from left to right and y is decreasing from top to bottom. So my idea was to pass x labels as a list: [-10, -9 ... 9, 9] and y labels as [9, 8 ... -9, -10]. This worked as intended in seaborn (matplotlib), however doing so in plotly just reverses the image vertically. Here's the code:

import numpy as np
import plotly.express as px

img = np.arange(20**2).reshape((20, 20))
fig = px.imshow(img,
            x=list(range(-10, 10)),
            y=list(range(-10, 10)),
            )
fig.show()

import numpy as np
import plotly.express as px

img = np.arange(20**2).reshape((20, 20))
fig = px.imshow(img,
            x=list(range(-10, 10)),
            y=list(reversed(range(-10, 10))),
            )
fig.show()

Why is this happening and how can I fix it?

【问题讨论】:

    标签: python plotly plotly-python


    【解决方案1】:
    import plotly.graph_objects as go
    import plotly.express as px
    
    img = np.arange(20**2).reshape((20, 20))
    fig = px.imshow(img,
        x=list(range(-10, 10)),
        y=list(range(10, 30, 1)),
    )
    
    fig.show()
    

    Output:

    【讨论】:

    • You just copied the code I already have in my post, lol. I want the top left coordinate to be (-10, 9), in your case it's (-10, -10).
    猜你喜欢
    • 2016-10-24
    • 2016-06-04
    • 2022-12-01
    • 1970-01-01
    • 2020-07-19
    • 2022-07-06
    • 2013-08-16
    • 2022-12-27
    • 2022-12-02
    相关资源
    最近更新 更多