Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly AttributeError: 'Figure' object has no attribute 'update_layout'

I am trying to add a title to my plot, but I get the error message:

"AttributeError: 'Figure' object has no attribute 'update_layout'"

The plot works without the update_layout line. I googled the error message without any luck.

Is there any other way to do this?

from _plotly_future_ import v4_subplots
from plotly.subplots import make_subplots
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.plotly as py

fig1 = make_subplots(
    rows=2, cols=2,
    specs=[[{"type": "pie"}, {"type": "pie"}],
           [{"type": "table"}, {"type": "table"}]],
)

fig1.add_trace(
    go.Pie(
        labels=pie_alarms_total['alarm_type'],
        values=pie_alarms_total['alarm_timestamp'],
        name="Total Alarms",
        title="test"
    ),
    row=1, col=1

)

fig1.add_trace(
    go.Pie(
        labels=pie_alarms_notbd['alarm_type'],
        values=pie_alarms_notbd['alarm_timestamp'],
        name="No TBDs"
    ),
    row=1, col=2
)

fig1.add_trace(
    go.Table(
        header=dict(
            values=pie_alarms_total['alarm_type'],
            line_color='darkslategray',
            fill_color='lightskyblue'
        ),
        cells=dict(
            values=pie_alarms_total['alarm_timestamp'],
            line_color='darkslategray',
            fill_color='lightcyan'
        )
    ),
    row=2, col=1
)

fig1.add_trace(
    go.Table(
        header=dict(
            values=pie_alarms_notbd['alarm_type'],
            line_color='darkslategray',
            fill_color='lightskyblue'
        ),
        cells=dict(
            values=pie_alarms_notbd['alarm_timestamp'],
            line_color='darkslategray',
            fill_color='lightcyan'
        )
    ),
    row=2, col=2
)

fig1.update_layout(title_text="Test")

plot(fig1, filename="test.html")

I want the main title for all the images on top.

like image 396
Alberto Rocha Avatar asked Jul 18 '19 20:07

Alberto Rocha


Video Answer


1 Answers

I found this issue in a Juan Klopper video. This is the wrong method call:

fig1.update_layout()

The correct way to update the figure layout is to call:

fig1.layout.update()
like image 177
Alberto Rocha Avatar answered Sep 16 '22 19:09

Alberto Rocha