How to add title to figure factory subplots

In the figure factory subplots “Vertical table an chart” example, I would like to know how to add a title to the table chart.

I was able to add a title by using make_suplots and setting subplot_titles but the title is not positionned correctly and I don’t know if I can change its position.

Hi @Yabadabadou,
Welcome to Plotly forum!
The plotly.figure_factory.create_table() is obsolete. To get the same plot use plotly.subplots.make_subplots
https://plotly.com/python/subplots/, and go.Table https://plotly.com/python/table/.
The following code defines the two subplots and moreover add title for table:

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(
    rows=2, cols=1,
    subplot_titles=('Bar plot title', 'Table title'),
    vertical_spacing=0.12,
    specs=[[{"type": "xy"}],
           [{"type": "table"}]]
)
# Add graph data
teams = ['Montréal Canadiens', 'Dallas Stars', 'NY Rangers',
         'Boston Bruins', 'Chicago Blackhawks', 'Ottawa Senators']
GFPG = [3.54, 3.48, 3.0, 3.27, 2.83, 3.18]
GAPG = [2.17, 2.57, 2.0, 2.91, 2.57, 2.77]

fig.add_trace(go.Bar(x=teams, y=GFPG, 
                marker=dict(color='#0099ff'),
                name='Goals For<br>Per Game'), 1,1)
fig.add_trace(go.Bar( x=teams, y=GAPG,
                marker=dict(color='#404040'),
                name='Goals Against<br>Per Game'),1,1)    
                

fig.add_trace(
    go.Table(
        header=dict(
            height=50,
            values=['<b>Team</b>', '<b>Wins</b>', '<b>Losses</b>', '<b>Ties</b>'],
            font_size=14,
            font_color='white',
            align="left",
        fill_color='#404040'
        ),
        cells=dict(
            values=[['Montréal<br>Canadiens',
                      'Dallas Stars',
                      'NY Rangers',
                      'Boston<br>Bruins',
                      'Chicago<br>Blackhawks',
                      'Ottawa<br>Senators'],  #data for the first table column
                      [18, 18, 16, 13, 13, 12],#            second column
                      [4, 5, 5, 8, 8, 5], #                 third column
                     [0, 0, 0, 0, 0, 0]],#                  fourth column
            align = "left",
           height=40)), row=2, col=1)
                
             
fig.update_layout(title_text='2016 Hokey Stats', height=900)
1 Like

Thank you very much empet for your answer!

I also figured out how to change the position of my subplots titles by updating the annotations:

fig['layout']['annotations'][0].update(x=0.5, y=0.91);
fig['layout']['annotations'][1].update(x=0.22, y=0.35);

@Yabadabadou Yes this is the way to insert subplot titles, but the figure_factory.create_table() is no longer mantained. That’s why it’s not recommended to use it.