Offline Tables, set font or background color on individual cells?

Hello,

In a Plotly Table (offline), Is there a way to specify the color for either the font or background of a particular cell? I see examples for colorscale, and setting entire rows, but I would like to set it for an individual cell. HTML β€œ<font color…” did not seem to work. Would like the color to be set based on the value of the data if possible

Thank you.

1 Like

#Imagine the table as a heatmap. For manipulating the shown values you have to set the annotations.
For setting the font color, e.g. positive values -> green // negative values -> red

for i in range(len(table.layout.annotations)):
    try:
        if float(table.layout.annotations[i]['text']) > 0.:
            table.layout.annotations[i].update(font=dict(color='green'))
        elif float(table.layout.annotations[i]['text']) < 0.:
            table.layout.annotations[i].update(font=dict(color='red'))
    except: #if cell has no value
        pass

I have not tested the following, but this is my idea:
For changing the cell, you have to set the z-coordinate of the table data to make use of the colorscale.
You get the data with this command:
table.data[0]['z']
For a correct implementation of the colorscale you have to scale your table data to values between 0 and 1 and overwrite the z-coordinate with these.