使用 Plotly imshow 函数时,我无法定义 x 和 y 绘图范围。
这是一些随机生成的数据和定义的绘图限制:
import numpy as np
img = np.random.randn(400,400)
xmin, xmax, ymin, ymax = 100, 200, 250, 350
使用 matplotlib,我可以执行以下操作来绘制数据并设置 x 和 y 绘图限制:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.imshow(img, cmap='gray')
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymax, ymin)
产生:
但是对于 Plotly,当我尝试用这段代码完成同样的事情时:
import plotly.express as px
fig = px.imshow(
img,
color_continuous_scale='gray',
)
fig.update_xaxes(range=[xmin, xmax])
fig.update_yaxes(range=[ymax, ymin])
fig.show()
如何使用 plotly 正确设置绘图的 x 和 y 限制?
编辑:我正在使用 Plotly 5.3.1 版



