考虑以下取自文档的热图示例:
import pandas as pd
import numpy as np
import plotly.express as px
# Create the index for the data frame
x = np.linspace(-1,1, 6)
y = np.linspace(-1,1,6)
n_channel = [1, 2, 3, 4]
xx, yy = np.meshgrid(x, y)
all_arrays = np.empty((0, 6, 6))
for n in n_channel:
z = np.random.randn(len(y), len(x))
all_arrays = np.vstack((all_arrays, [z]))
fig = px.imshow(
all_arrays,
facet_col=0,
)
for k in range(4):
fig.layout.annotations[k].update(text='n_channel:{}'.format(k))
fig.show()
产生以下情节
我想要一个 等高线图,它共享轴和颜色条。鉴于两种类型的图之间的相似性,我期望这可以通过简单地将
imshow
替换为 contour
来实现。然而事实并非如此。
如何做到这一点?