title: How to refresh a plotly figure after dataframe update?
body: <p>Let's say that you've built a figure using <code>px.line()</code> using a dataframe, and the dataframe later has new data added to it. What's a good approach to refresh your figure with new data? An example could be <code>px.data.stocks</code>, where you start out with a subset of the columns <code>['GOOG', 'AAPL', 'AMZN', 'FB', 'NFLX', 'MSFT']</code>, for example <code>['GOOG', 'AAPL']</code>, and that after building the figure, <code>['AMZN', 'FB', 'NFLX', 'MSFT']</code> is added to the dataframe.</p>
  <h3>Example plot</h3>
  <p><a href="https://i.stack.imgur.com/lukyR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lukyR.png" alt="enter image description here" /></a></p>
  <h3>Example code</h3>
  <pre><code># imports
  import pandas as pd
  import plotly.express as px
  import plotly.graph_objects as go
  
  # data
  df = px.data.stocks().set_index('date')
  df.index = pd.to_datetime(df.index)
  
  # figure
  fig = px.line(df, x = df.index, y = df.columns[:2])
  fig.show()
  </code></pre>