我有一个宽矩阵,我用巧妙的表达方式呈现出来。让我们说:
import plotly.express as px
data=[[1, 25, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, 5, 20]]
fig = px.imshow(data,
labels=dict(x="Day of Week", y="Time of Day", color="Productivity"),
x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
y=['Morning', 'Afternoon', 'Evening']
)
fig.update_xaxes(side="top")
fig.layout.height = 500
fig.layout.width = 500
fig.show()为了提高可读性,我想在矩阵的右侧重复(或添加一个相同的) yaxis。
我试着跟踪这
fig.update_layout(xaxis=dict(domain=[0.3, 0.7]),
# create 1st y axis
yaxis=dict(
title="yaxis1 title",),
# create 2nd y axis
yaxis2=dict(title="yaxis2 title", anchor="x", overlaying="y",
side="right")
)但是我不能让它与imshow一起工作,因为它不接受yaxis参数。
有什么解决办法吗?
发布于 2022-10-17 06:27:36
通过圆滑的论坛找到了一个答案
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
data=[[1, 25, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, 5, 20]]
fig.add_trace(go.Heatmap(
z=data,
x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
y=['Morning', 'Afternoon', 'Evening']
),secondary_y=False)
fig.add_trace(go.Heatmap(
z=data,
x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
y=['Morning', 'Afternoon', 'Evening']
),secondary_y=True)
fig.update_xaxes(side="top")
fig.update_layout(xaxis_title="Day of Week", yaxis_title="Time of Day")
fig.show()请注意,添加两次跟踪可能不是最优的,但它有效。
https://stackoverflow.com/questions/74056192
复制相似问题