I had been running a code in Jupyter Notebook that had been working fine before. Iām using version 4.5.0 of plotly. The code added traces and output a plot, but now I see the error:
AttributeError: āFigureā object has no attribute āupdate_layoutā
I commented out the update_layout part, but now it looks like the figure simply doesnt show up. This is what my original function that was working looks like:
import pandas as pd
import numpy as np
import plotly.graph_objects as go
import datetime as dt
def create_scatter(df,ticker_list,y_column_list,title_name='',xlabel='',ylabel=''):
fig = go.Figure()
for y in y_column_list:
for t in ticker_list:
fig.add_trace(go.Scatter(x=df[df.entity_code == t].date,y=df[df.entity_code == t][y],name=t))
fig.update_layout(
title={'text': title_name,
'y':0.9,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
xaxis_title=xlabel,
yaxis_title=ylabel,
showlegend=True)
fig.show()
Any help would be appreciated, thank you!
Update: Even when I run the example code in the documentation, I get the same attribute error.
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
y=[0, 1, 2, 3, 4, 5, 6, 7, 8],
name=āName of Trace 1ā # this sets its legend entry
))
fig.add_trace(go.Scatter(
x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
y=[1, 0, 3, 2, 5, 4, 7, 6, 8],
name=āName of Trace 2ā
))
fig.update_layout(
title=āPlot Titleā,
xaxis_title=āx Axis Titleā,
yaxis_title=āy Axis Titleā,
font=dict(
family=āCourier New, monospaceā,
size=18,
color="#7f7f7f"
)
)
fig.show()