TestGuest
TestGuest

Reputation: 603

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:

enter image description here

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?

Upvotes: 23

Views: 23221

Answers (5)

JacobLasky
JacobLasky

Reputation: 41

None of these were working for me but doing this updated it without any issue:

fig = ...
fig.data[0].colorbar.title = "Title Here"

Upvotes: 2

Miladiouss
Miladiouss

Reputation: 4700

fig = ...
fig.layout.coloraxis.colorbar.title = 'Title<br>Here'

Upvotes: 3

Piotro
Piotro

Reputation: 665

You can also do it after by updating the layout:

fig.update_layout(
    coloraxis_colorbar=dict(
        title="Your Title",
    ),
)

Upvotes: 12

vestland
vestland

Reputation: 61104

Just include colorbar={"title": 'Your title'} in go.Heatmap() to get this:

Plot:

enter image description here

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()

Upvotes: 15

abhilb
abhilb

Reputation: 5757

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()

Upvotes: 13

Related Questions