【问题标题】:how to show numpy array imshow plotly as frames?如何将 numpy 数组 imshow 显示为帧?
【发布时间】:2021-07-30 10:26:44
【问题描述】:

创建一个数组并从中制作图片

xg = np.random.rand(100, 22400)
fig = px.imshow(a,aspect="auto", color_continuous_scale='gray')
out1.show()

问题是数组很长,图不能正常工作,是否可以分帧显示数组(因为每个值都已经是一个像素了)?

【问题讨论】:

    标签: python python-3.x plotly plotly-python


    【解决方案1】:
    • 您可以使用animations 分割成帧
    • 已对 numpy 数组进行切片以创建帧
    import numpy as np
    import plotly.graph_objects as go
    import plotly.express as px
    
    xg = np.random.rand(100, 22400)
    # xg = np.random.rand(10, 1200)
    
    base = px.imshow(xg, aspect="auto", color_continuous_scale="gray")
    frameSize = 400
    
    frames = [
        go.Frame(
            data=px.imshow(
                xg[:, x : x + frameSize], aspect="auto", color_continuous_scale="gray"
            ).data,
            name=x,
        )
        for x in range(0, xg.shape[1], frameSize)
    ]
    
    go.Figure(data=frames[0].data, frames=frames, layout=base.layout).update_layout(
        updatemenus=[{
            "buttons": [{"args": [None, {"frame": {"duration": 500, "redraw": True}}],
                        "label": "▶",
                        "method": "animate",
                    },],
            "type": "buttons",
            }],
        sliders=[{
            "steps": [{"args": [[d],
                                {"frame": {"duration": 0, "redraw": True},
                                 "mode": "immediate",},],
                        "label": d,
                        "method": "animate",
                      }
                      for d in range(0, xg.shape[1], frameSize)
                     ],
            }],
    )
    

    【讨论】:

    • 看起来我需要,但不明白为什么base.show () 不起作用
    • base 不是动画...你可以做fig = go.Figure(... 然后fig.show()。我在 jupyter notebook 中运行所以不需要.show()
    • 谢谢,一切都很好。使用滑块时,有什么方法可以使 'y' 轴从该位置变为实数?
    • 是x轴不显示绝对位置,是滑块+x轴。我看不到每帧都改变 x 轴的方法...
    猜你喜欢
    • 2021-08-29
    • 1970-01-01
    • 2014-11-06
    • 2011-02-09
    • 2016-02-23
    • 2021-07-19
    • 2018-08-15
    • 1970-01-01
    相关资源
    最近更新 更多