leuschnm commited on
Commit
142ddb8
·
1 Parent(s): bc7b5a0
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -148,27 +148,29 @@ def main():
148
  preds = predict(model, dataloader, st.session_state.date)
149
  update_plot(df, preds, axs, fig)
150
 
151
- def update_plot2(ax):
152
- x = np.linspace(0, 2*np.pi, 100)
153
- y = np.sin(x)
154
- ax.plot(x, y, label='New Line')
 
 
 
 
 
 
155
  ax.legend()
156
- st.pyplot()
157
-
158
- # Create an initial plot
159
- figs, ax = plt.subplots()
160
- x_initial = np.linspace(0, 2*np.pi, 100)
161
- y_initial = np.cos(x_initial)
162
- ax.plot(x_initial, y_initial, label='Initial Line')
163
- ax.set_xlabel('X-axis')
164
- ax.set_ylabel('Y-axis')
165
- ax.set_title('Plot')
166
- ax.legend()
167
- st.pyplot(figs)
168
 
169
- # Button to update the plot
170
  if st.button('Add Line'):
171
- update_plot2(ax)
 
 
 
 
 
172
 
173
 
174
 
 
148
  preds = predict(model, dataloader, st.session_state.date)
149
  update_plot(df, preds, axs, fig)
150
 
151
+
152
+ @st.cache(allow_output_mutation=True)
153
+ def create_plot():
154
+ fig, ax = plt.subplots()
155
+ x_initial = np.linspace(0, 2*np.pi, 100)
156
+ y_initial = np.cos(x_initial)
157
+ ax.plot(x_initial, y_initial, label='Initial Line')
158
+ ax.set_xlabel('X-axis')
159
+ ax.set_ylabel('Y-axis')
160
+ ax.set_title('Plot')
161
  ax.legend()
162
+ return fig
163
+
164
+ fig = create_plot()
165
+ st.pyplot(fig)
 
 
 
 
 
 
 
 
166
 
 
167
  if st.button('Add Line'):
168
+ ax = fig.axes[0]
169
+ x_new = np.linspace(0, 2*np.pi, 100)
170
+ y_new = np.sin(x_new)
171
+ ax.plot(x_new, y_new, label='New Line')
172
+ ax.legend()
173
+ st.pyplot(fig)
174
 
175
 
176