Skip to content

Plotly GO Table adds x-axis/y-axis elements when adding annotation #4090

@bderider100

Description

@bderider100

Hi,

I have a function to return a GO Table. When adding an annotation to this table, it puts an x-axis and y-axis, populated with generic numbers. Not understanding why this would display with a table.

Expected behavior is that the caption would appear outside of the table area and that x-axis and y-axis elements wouldn't be shown. Below is an image of an output table, the function code, and the code that converts the plotly visual into an image.

I am making an issue on github because I believe this to be a bug. I tried to do a good faith search of open issues, but didn't see anything. Additionally, I tried to search all official and unofficial documentation on GO tables, but didn't find anything that elucidated this. I have functions for px.bar and px.line that doesn't add any unwanted elements yet adds the caption in the exact spot as what is shown.

Example plot:
Example_PLOTLY_GO_table

Code:

def returnPlotlyGoTable(pdfData, dictChartText, strFillColorCols = 'lightsteelblue', strAlignCols = 'left', strFillColorVals = 'lightgray', strAlignVals = 'left'): 
    tmpFig = go.Figure(data = [go.Table(header = dict(values = list(pdfData.columns),                         
                                                      fill_color = strFillColorCols, 
                                                      align = strAlignCols), 
                                                      cells = dict(values = pdfData.transpose().values.tolist(), 
                                                                   fill_color = strFillColorVals, 
                                                                   align = strAlignVals, 
                                                                   format = dictChartText['d3fmt']
                                                                  )
                                       )
                              ]
                      )
    
    if 'title' in dictChartText.keys() and dictChartText['title'] != '': 
        tmpFig.update_layout(title_text = dictChartText['title'])
    tmpFig.update_layout(margin = dict(t = 150))
    if 'caption' in dictChartText.keys() and dictChartText['caption'] != '': 
        tmpFig.add_annotation(font = dict(color = 'black', size = 12), 
                                     x = 0, 
                                     y = 1.06, 
                                     showarrow = False, 
                                     text = dictChartText['caption'], 
                                     textangle = 0, 
                                     xref = 'x', 
                                     yref = 'paper'
                               )
        tmpFig.update_layout()
    return tmpFig

Code snippet 2

imgTmp = BytesIO(key2.to_image(format = 'png', width = 1980, height = 1080))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions