Graphics update

Hello. There is a program that I have prepared in Python PyQt5. It may be simple for you, but I could not solve it. There are charts that I created with the data I obtained with Plotly. When new data arrives, I want the old graph to be deleted and the new graph loaded. How can I do that. I would be grateful if you help. Thank you.


#       from PyQt5.QtWebEngineWidgets import*
         from plotly.graph_objects import Figure, Scatter
         import plotly.graph_objects as go
         from plotly.graph_objects import*
         import plotly 
         self.fig.data=[self.fig.data[0],self.fig.data[1],self.fig.data[2]]
         self.fig = Figure(Bar(x=donemler1, y=donemkarzarar1,name="Çeyreklik Satışlar"))#
         self.fig.add_trace(Bar(x=donemler2, y=donemkarzarar2,name="Çeyreklik Net Kar", ))#line_color='#ffe476'
         self.fig.add_trace(Bar(x=donemler3, y=donemkarzarar3,name="Çeyreklik Favök", ))#line_color='#b9d3ee'
         
         self.fig.update_layout(autosize=False,width=690,height=380,margin=dict(t=0, b=0, l=0, r=0),template="plotly_white",legend_title_text=str(self.ui.HisseSec.currentText())+' - Çeyreklik Veriler',legend=dict(orientation="h",yanchor="bottom",y=1.02,xanchor="right",x=1))
         self.fig.update_xaxes(showgrid=False)
         self.fig.update_yaxes(showgrid=False)
         

         # we create html code of the figure
         html = '<html><body>'
         html += plotly.offline.plot(self.fig, output_type='div', include_plotlyjs='cdn',config = {'displayModeBar': False})
         
         html += '</body></html>'

         # we create an instance of QWebEngineView and set the html code
         self.plot_widget = QWebEngineView()
         self.plot_widget.setHtml(html)

         # # set the QWebEngineView instance as main widget
         self.layoutsatis=QVBoxLayout(self.ui.grafikceyreksatis)
         self.layoutsatis.setContentsMargins(0,0,0,0)
         self.layoutsatis.addWidget(self.plot_widget)
         
         self.setLayout(self.layoutsatis)


Please can someone help?

Hi,

Welcome to the community! :slightly_smiling_face:

This is a PyQt5 question, so I would recommend you to post it on SO to increase your chances of getting help.

Thank you. I solved my problem. But this time there are traces on the graphic, I cannot delete them. Even though I did fig.data= and fig.layout={} the tracks are not deleted.

Sorry for the late reply, I was a bit away from the forum for a while… :slightly_smiling_face:

Can you add a print(self.fig.to_dict()) in your code and post the output before and after updating the figure here?