shaik moeed
shaik moeed

Reputation: 5785

Plotly: Added title to colorbar but not able to see on plot

I have tried to add title to colorbar but not able to see on plot.

Code:

fig = go.Figure(go.Scatter(
    x=df['Date'],
    y = df["GC1"],
    mode='markers',
    # showlegend = True,
    hovertext=df['MM_ln'],
    hoverlabel=dict(namelength=0),
    hovertemplate='%{hovertext}<br>Date: %{x} <br>MM_l: %{y}',
    marker=dict(
        size=df["GC1"]*0.01,
        color=df["MM_l_cc"], #set color to MM_l_cc
        colorscale='Viridis', # one of plotly colorscales
        showscale=True,
    )
))

# fig.layout.coloraxis.colorbar.title = 'Title'
fig.update_layout(
    title='Positioning price concentration MM_l',
    xaxis_title='Weekly observations',
    yaxis_title='Gold price',
    meta=dict(colorbar=dict(title="Title"))
    )


# fig.layout.coloraxis.colorbar.title = 'another title'
fig.show()

Ouput:

enter image description here

Where is the mistake? How to solve this? Can anyone please suggest?

Upvotes: 2

Views: 954

Answers (2)

shaik moeed
shaik moeed

Reputation: 5785

I was able to see the title, after adding colorbar inside marker in my code as

marker=dict(
        ...
        colorbar={"title": "Your title"},
    )

Upvotes: 0

Samuell Kovacs
Samuell Kovacs

Reputation: 11

You can include it in go.Scatter() like so

import plotly.graph_objects as go
fig = go.Figure(data=go.Scatter(colorbar={"title": "Your title"},
                                            z=[[1, 20, 30],
                                              [20, 1, 60],
                                              [30, 60, 1]]))
fig.show()

or you can include it in the layout update like so

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

Upvotes: 1

Related Questions