Search code examples
pythonplotlyjoblib

Plotly: How to change table font size using fig.update?


I generate plotly tables with plolty. is it possible to set the font size with fig.update?

import plotly.graph_objects as go
import joblib

fig = go.Figure(data=[go.Table(header=dict(values=['A Scores', 'B Scores']),
                 cells=dict(values=[[100, 90, 80, 90], [95, 85, 75, 95]]))
                     ])
#fig.update(set font_size here
fig.show()

the background is that I use the table in a pdf but also in a plotly dashboard. this is possible with joblib. for the pdf the font size is suitable. for the dashboard i would like to change it again after calling it. For example, for charts I can still change the legend with fig.update_layout(legend=dict( font=dict(size=5)). does this also work with a table?


Solution

  • You can run:

    fig.update_traces(cells_font=dict(size = 15))
    

    Which will give you this:

    enter image description here

    Instead of the default:

    enter image description here

    Complete code:

    import plotly.graph_objects as go
    # import joblib
    
    fig = go.Figure(data=[go.Table(header=dict(values=['A Scores', 'B Scores']),
                     cells=dict(values=[[100, 90, 80, 90], [95, 85, 75, 95]]))
                         ])
    #fig.update(set font_size here
    f = fig.full_figure_for_development(warn=False)
    fig.show()
    fig.update_traces(cells_font=dict(size = 15))
    fig.show()