MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Matplotlib_Embedded_TEMPLATE.py:185–217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

183# ----------------------------- The GUI Section -----------------------------
184
185def main():
186 dictionary_of_figures = {'Axis Grid': create_axis_grid,
187 'Subplot 3D': create_subplot_3d,
188 'Scales': create_pyplot_scales,
189 'Basic Figure': create_figure}
190
191
192 left_col = [[sg.T('Figures to Draw')],
193 [sg.Listbox(list(dictionary_of_figures), default_values=[list(dictionary_of_figures)[0]], size=(15, 5), key='-LB-')],
194 [sg.T('Matplotlib Styles')],
195 [sg.Combo(plt.style.available, key='-STYLE-')]]
196
197 layout = [ [sg.T('Matplotlib Example', font='Any 20')],
198 [sg.Column(left_col), sg.Image(key='-IMAGE-')],
199 [sg.B('Draw'), sg.B('Exit')] ]
200
201 window = sg.Window('Matplotlib Template', layout)
202
203 image_element = window['-IMAGE-'] # type: sg.Image
204
205 while True:
206 event, values = window.read()
207 print(event, values)
208 if event == 'Exit' or event == sg.WIN_CLOSED:
209 break
210 if event == 'Draw' and values['-LB-']:
211 # Get the function to call to make figure. Done this way to get around bug in Web port (default value not working correctly for listbox)
212 func = dictionary_of_figures.get(values['-LB-'][0], list(dictionary_of_figures.values())[0])
213 if values['-STYLE-']:
214 plt.style.use(values['-STYLE-'])
215 draw_figure(image_element, func())
216
217 window.close()
218
219
220if __name__ == "__main__":

Calls 5

readMethod · 0.95
closeMethod · 0.95
valuesMethod · 0.80
draw_figureFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected