Draws the previously created "figure" in the supplied Image Element :param element: an Image Element :param figure: a Matplotlib figure :return: The figure canvas
(element, figure)
| 160 | # ----------------------------- The draw figure helpful function ----------------------------- |
| 161 | |
| 162 | def draw_figure(element, figure): |
| 163 | """ |
| 164 | Draws the previously created "figure" in the supplied Image Element |
| 165 | |
| 166 | :param element: an Image Element |
| 167 | :param figure: a Matplotlib figure |
| 168 | :return: The figure canvas |
| 169 | """ |
| 170 | |
| 171 | |
| 172 | plt.close('all') # erases previously drawn plots |
| 173 | canv = FigureCanvasAgg(figure) |
| 174 | buf = io.BytesIO() |
| 175 | canv.print_figure(buf, format='png') |
| 176 | if buf is None: |
| 177 | return None |
| 178 | buf.seek(0) |
| 179 | element.update(data=buf.read()) |
| 180 | return canv |
| 181 | |
| 182 | |
| 183 | # ----------------------------- The GUI Section ----------------------------- |