Activate the given backend and set interactive to True.
(backend)
| 304 | |
| 305 | |
| 306 | def activate_matplotlib(backend): |
| 307 | """Activate the given backend and set interactive to True.""" |
| 308 | |
| 309 | import matplotlib |
| 310 | matplotlib.interactive(True) |
| 311 | |
| 312 | # Matplotlib had a bug where even switch_backend could not force |
| 313 | # the rcParam to update. This needs to be set *before* the module |
| 314 | # magic of switch_backend(). |
| 315 | matplotlib.rcParams['backend'] = backend |
| 316 | |
| 317 | # Due to circular imports, pyplot may be only partially initialised |
| 318 | # when this function runs. |
| 319 | # So avoid needing matplotlib attribute-lookup to access pyplot. |
| 320 | from matplotlib import pyplot as plt |
| 321 | |
| 322 | plt.switch_backend(backend) |
| 323 | |
| 324 | plt.show._needmain = False |
| 325 | # We need to detect at runtime whether show() is called by the user. |
| 326 | # For this, we wrap it into a decorator which adds a 'called' flag. |
| 327 | plt.draw_if_interactive = flag_calls(plt.draw_if_interactive) |
| 328 | |
| 329 | |
| 330 | def import_pylab(user_ns, import_all=True): |
nothing calls this directly
no test coverage detected