如何将 numpy 数组 imshow plotly 显示为帧?
how to show numpy array imshow plotly as frames?
创建一个数组并用它制作图片
xg = np.random.rand(100, 22400)
fig = px.imshow(a,aspect="auto", color_continuous_scale='gray')
out1.show()
问题是数组很长,图形无法正常显示,是否可以按帧显示数组(因为每个值已经是一个像素)?
- 你可以使用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)
],
}],
)
创建一个数组并用它制作图片
xg = np.random.rand(100, 22400)
fig = px.imshow(a,aspect="auto", color_continuous_scale='gray')
out1.show()
问题是数组很长,图形无法正常显示,是否可以按帧显示数组(因为每个值已经是一个像素)?
- 你可以使用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)
],
}],
)