Zdravicko.
Snazim sa generovat graf do aplikacie a nasledne po kliku na update refreshnut. Na nete je x prikladov ako na to ale mne to nechce fungovat. Vedel by niekto poradit?
Toto je cast kde volam skrz PySimpleGui graf
while True:
if database_connection == True and socket_communication == True and model_is_selected == 'On':
main_loop()
# This need to be deleted
if update_graph == True:
data_for_graph()
update_graph = False
else:
if (database_connection == False):
print('Connecting to SQL ..')
Connect_SQL()
if (socket_communication == False):
print('Communication via Socket ...')
Socket_connection()
event, values = window.read(timeout=200)
if event is None: # if user closes window
break
if event == "update":
if fig_agg is not None:
delete_fig_agg(fig_agg)
time.sleep(1)
data_for_graph()
fig = fig_maker(window)
fig_agg = draw_figure(window['canvas'].TKCanvas, fig)
window.Refresh()
if update_graph == True:
if fig_agg is not None:
delete_fig_agg(fig_agg)
time.sleep(1)
fig_agg = draw_figure(window['canvas'].TKCanvas, fig)
window.Refresh()
A toto je zvysok kde to kontrolujem
def fig_maker(window): # this should be called as a thread, then time.sleep() here would not freeze the GUI
global fig
global reults_graph
global diff_graph
global min_graph
global max_graph
ax = fig.add_subplot(111)
difference = float(difference_weight)
difference_min = float(difference_weight) - float(low_limit)
difference_max = float(difference_weight) + float(max_limit)
low_for_graph = difference_min - 3
hight_for_graph = difference_max + 3
ax.set_ylim(low_for_graph,hight_for_graph)
ax.plot(reults_graph,color='green', marker='o', label = 'Posledné hodnoty')
ax.plot(diff_graph,color='orange', label = 'Požadovaná váha' )
ax.plot(min_graph,color='red', label = 'Min - Max limit')
ax.plot(max_graph,color='red')
ax.legend(loc="upper left")
ax.grid()
return plt.gcf()
# draw graph
def draw_figure(canvas, figure, loc=(0, 0)):
figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)
figure_canvas_agg.draw()
figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)
return figure_canvas_agg
# delete actual graph
def delete_fig_agg(fig_agg):
fig_agg.get_tk_widget().forget()
plt.close('all')
problem bude return s fig_maker(window) return plt.gcf() ale neviem ako donho napchat moj graf.