How to add caption & subtitle in the plot

I need help in adding caption & subtitle in the plot…(Here you can take any example of your choice to add caption and subtitle)

My Code

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Bar(x=[“Orange”, ‘Mango’, ‘Banana’], y=[4000, 3000, 5000]))

fig.show()

Hi @maddy6,

You have two options:

  1. Set the caption as `xaxis_title:
import numpy as np
import plotly.graph_objects as go

scatt = go.Scatter(x=[1, 2, 3, 4], y=[3, 0, 6, 2], mode='lines', line_color='Royalblue')
layout1 = go.Layout(width=600, xaxis_title='Your caption')
fig1 = go.Figure(data=[scatt], layout=layout1)
fig1.show()
  1. Keep xaxis_title for what it is designed, and insert caption as an annotation:
layout2 = go.Layout(width=600, xaxis_title='x', yaxis_title='y',
                    margin_b=90, #increase the bottom margin to have space for caption
                    annotations = [dict(xref='paper',
                                        yref='paper',
                                        x=0.5, y=-0.25,
                                        showarrow=False,
                                        text ='This is my caption for the Plotly figure')])

fig2 = go.Figure(data=[scatt], layout=layout2)
fig2.show()
1 Like