Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 728
TestGuest Avatar asked Nov 26 '19 21:11

TestGuest


People also ask

How do I change my color palette in Plotly?

Just run dir(px. colors. qualitative) to see what are available to you in the plotly version you are running: ['Alphabet', 'Antique', 'Bold', 'D3', 'Dark2', 'Dark24', 'G10',......]

How do I remove the Colorbar in Plotly?

In this example, we are hiding color-bar in Plotly Express with the help of method fig. update_coloraxes(showscale=False), by passing the showscale parameter as False.

What is Plotly Graph_objects in Python?

The plotly. graph_objects module (typically imported as go ) contains an automatically-generated hierarchy of Python classes which represent non-leaf nodes in this figure schema. The term "graph objects" refers to instances of these classes. The primary classes defined in the plotly.


1 Answers

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()
like image 133
abhilb Avatar answered Sep 19 '22 02:09

abhilb