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)
| 78 | # dP |
| 79 | |
| 80 | def draw_figure(element, figure): |
| 81 | """ |
| 82 | Draws the previously created "figure" in the supplied Image Element |
| 83 | |
| 84 | :param element: an Image Element |
| 85 | :param figure: a Matplotlib figure |
| 86 | :return: The figure canvas |
| 87 | """ |
| 88 | |
| 89 | plt.close('all') # erases previously drawn plots |
| 90 | canv = FigureCanvasAgg(figure) |
| 91 | buf = io.BytesIO() |
| 92 | canv.print_figure(buf, format='png') |
| 93 | if buf is not None: |
| 94 | buf.seek(0) |
| 95 | element.update(data=buf.read()) |
| 96 | return canv |
| 97 | else: |
| 98 | return None |
| 99 | |
| 100 | |
| 101 |