[英]Title for colorbar in Plotly Heatmap
This is my code:这是我的代码:
fig = go.Figure(
data=go.Heatmap(z=z_values, y=[str(x) for x in params_1], x=[str(x) for x in params_2]),
layout=go.Layout(
title="Analysis results",
xaxis=dict(title='Diameter'),
yaxis=dict(title='Max Distance')
),
)
fig.show()
It generates a 2D-heatmap (snippet below), but I'd like to include a title for the colorbar:它会生成一个 2D 热图(下面的片段),但我想为颜色条添加一个标题:
Unfortunately the plotly example also does not have a colorbar title.不幸的是,情节示例也没有颜色条标题。 I have tried to include the colorbar properties with the "marker" but this throws an error.我试图将颜色栏属性包含在“标记”中,但这会引发错误。 How can I do that hence?我该怎么做呢?
Try尝试
fig = go.Figure(
data=go.Heatmap(z=z_values, y=[str(x) for x in params_1], x=[str(x) for x in params_2]),
colorbar=dict(title='Title') ,
layout=go.Layout(
title="Analysis results",
xaxis=dict(title='Diameter'),
yaxis=dict(title='Max Distance')
),
)
fig.show()
Just include colorbar={"title": 'Your title'}
in go.Heatmap()
to get this:只需在go.Heatmap()
包含colorbar={"title": 'Your title'}
即可获得:
Plot:阴谋:
Code:代码:
import plotly.graph_objects as go
fig = go.Figure(data=go.Heatmap(colorbar={"title": "Your title"},
z=[[1, 20, 30],
[20, 1, 60],
[30, 60, 1]]))
fig.show()
You can also do it after by updating the layout:您也可以在更新布局后执行此操作:
fig.update_layout(
coloraxis_colorbar=dict(
title="Your Title",
),
)
fig = ... fig.layout.coloraxis.colorbar.title = 'Title<br>Here'
None of these were working for me but doing this updated it without any issue:这些都不适合我,但这样做更新它没有任何问题:
fig = ...
fig.data[0].colorbar.title = "Title Here"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.