Moved visibility setting out of the drawing function for better performance
This commit is contained in:
parent
35dd8b3df1
commit
c48968b36d
|
@ -63,6 +63,7 @@ def your_matplotlib_code():
|
||||||
# ooooooooooooooooooooooooooooo of your Matplotlib code
|
# ooooooooooooooooooooooooooooo of your Matplotlib code
|
||||||
|
|
||||||
|
|
||||||
|
# ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||||
|
|
||||||
|
|
||||||
# dP dP dP
|
# dP dP dP
|
||||||
|
@ -71,7 +72,7 @@ def your_matplotlib_code():
|
||||||
# 88 88 88ooood8 88 88' `88 88ooood8 88' `88
|
# 88 88 88ooood8 88 88' `88 88ooood8 88' `88
|
||||||
# 88 88 88. ... 88 88. .88 88. ... 88
|
# 88 88 88. ... 88 88. .88 88. ... 88
|
||||||
# dP dP `88888P' dP 88Y888P' `88888P' dP
|
# dP dP `88888P' dP 88Y888P' `88888P' dP
|
||||||
# ooooooooooooooooooooooo~88~oooooooooooooooooooooooo function
|
# ooooooooooooooooooooooo~88~oooooooooooooooooooooooo function starts below
|
||||||
# dP
|
# dP
|
||||||
|
|
||||||
def draw_figure(element, figure):
|
def draw_figure(element, figure):
|
||||||
|
@ -87,11 +88,12 @@ def draw_figure(element, figure):
|
||||||
canv = FigureCanvasAgg(figure)
|
canv = FigureCanvasAgg(figure)
|
||||||
buf = io.BytesIO()
|
buf = io.BytesIO()
|
||||||
canv.print_figure(buf, format='png')
|
canv.print_figure(buf, format='png')
|
||||||
if buf is None:
|
if buf is not None:
|
||||||
return None
|
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
element.update(data=buf.read(), visible=True)
|
element.update(data=buf.read())
|
||||||
return canv
|
return canv
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,6 +122,7 @@ def main():
|
||||||
break
|
break
|
||||||
elif event == 'Ok':
|
elif event == 'Ok':
|
||||||
draw_figure(window['-IMAGE-'], your_matplotlib_code())
|
draw_figure(window['-IMAGE-'], your_matplotlib_code())
|
||||||
|
window['-IMAGE-'].update(visible=True)
|
||||||
elif event == 'Clear':
|
elif event == 'Clear':
|
||||||
plt.close('all') # close all plots
|
plt.close('all') # close all plots
|
||||||
window['-IMAGE-'].update() # clears the image
|
window['-IMAGE-'].update() # clears the image
|
||||||
|
|
Loading…
Reference in New Issue