Ensures that pyplot has been imported into the embedded IPython shell. Also, makes sure to set the backend appropriately if not set already.
(self)
| 759 | return ret, image_directive |
| 760 | |
| 761 | def ensure_pyplot(self): |
| 762 | """ |
| 763 | Ensures that pyplot has been imported into the embedded IPython shell. |
| 764 | |
| 765 | Also, makes sure to set the backend appropriately if not set already. |
| 766 | |
| 767 | """ |
| 768 | # We are here if the @figure pseudo decorator was used. Thus, it's |
| 769 | # possible that we could be here even if python_mplbackend were set to |
| 770 | # `None`. That's also strange and perhaps worthy of raising an |
| 771 | # exception, but for now, we just set the backend to 'agg'. |
| 772 | |
| 773 | if not self._pyplot_imported: |
| 774 | if 'matplotlib.backends' not in sys.modules: |
| 775 | # Then ipython_matplotlib was set to None but there was a |
| 776 | # call to the @figure decorator (and ipython_execlines did |
| 777 | # not set a backend). |
| 778 | #raise Exception("No backend was set, but @figure was used!") |
| 779 | import matplotlib |
| 780 | matplotlib.use('agg') |
| 781 | |
| 782 | # Always import pyplot into embedded shell. |
| 783 | self.process_input_line('import matplotlib.pyplot as plt', |
| 784 | store_history=False) |
| 785 | self._pyplot_imported = True |
| 786 | |
| 787 | def process_pure_python(self, content): |
| 788 | """ |
no test coverage detected