【发布时间】:2021-05-01 11:06:34
【问题描述】:
我正在 python 中使用plotly 绘制热图。我想在某些区域周围画一个矩形,我这样做如下:
import plotly.graph_objs as go
import plotly.figure_factory as ff
layout_heatmap = go.Layout(
xaxis=dict(title='Years'),
yaxis=dict(title='Years'),
)
ff_fig = ff.create_annotated_heatmap(x=all_years, y=all_years, z=heatmap, showscale=True,
colorscale='Viridis',)
fig = go.FigureWidget(ff_fig)
fig.layout = layout_heatmap
fig.layout.annotations = ff_fig.layout.annotations
fig['layout']['yaxis']['autorange'] = "reversed"
fig.add_shape(type="rect",
x0=1960, y0=1960, x1=1966, y1=1966,
line=dict(color="red"),
)
fig.add_shape(type="rect",
x0=1967, y0=1967, x1=1970, y1=1970,
line=dict(color="red"),
)
fig.show()
【问题讨论】:
-
我的建议最后对你有什么效果?
-
@vestland 嗨,不幸的是我无法让它工作,我很确定你的代码是正确的,但我不知道为什么在我的工作区它不工作。可能是版本问题
-
好的,感谢您的快速反馈!您是否有机会考虑将我的建议标记为已接受的答案?如果有更好的解决方案出现,这总是可以撤消的。
-
@vestland 也感谢您提供详细的反馈和代码,它确实有很大帮助。
-
不客气!当您有机会在更新版本上进行测试时,请务必回来查看。
标签: python plotly line heatmap