Args: Same as in :meth:`__init__()`. Returns: fig (matplotlib.pyplot.figure): top level container for all the image plot elements. ax (matplotlib.pyplot.Axes): contains figure elements and sets the coordinate system.
(self, img)
| 267 | self._setup_figure(img) |
| 268 | |
| 269 | def _setup_figure(self, img): |
| 270 | """ |
| 271 | Args: |
| 272 | Same as in :meth:`__init__()`. |
| 273 | |
| 274 | Returns: |
| 275 | fig (matplotlib.pyplot.figure): top level container for all the image plot elements. |
| 276 | ax (matplotlib.pyplot.Axes): contains figure elements and sets the coordinate system. |
| 277 | """ |
| 278 | fig = mplfigure.Figure(frameon=False) |
| 279 | self.dpi = fig.get_dpi() |
| 280 | # add a small 1e-2 to avoid precision lost due to matplotlib's truncation |
| 281 | # (https://github.com/matplotlib/matplotlib/issues/15363) |
| 282 | fig.set_size_inches( |
| 283 | (self.width * self.scale + 1e-2) / self.dpi, |
| 284 | (self.height * self.scale + 1e-2) / self.dpi, |
| 285 | ) |
| 286 | self.canvas = FigureCanvasAgg(fig) |
| 287 | # self.canvas = mpl.backends.backend_cairo.FigureCanvasCairo(fig) |
| 288 | ax = fig.add_axes([0.0, 0.0, 1.0, 1.0]) |
| 289 | ax.axis("off") |
| 290 | self.fig = fig |
| 291 | self.ax = ax |
| 292 | self.reset_image(img) |
| 293 | |
| 294 | def reset_image(self, img): |
| 295 | """ |