Ensures that pyplot has been imported into the embedded IPython shell. Also, makes sure to set the backend appropriately if not set already.
(self)
| 779 | return ret, image_directive |
| 780 | |
| 781 | def ensure_pyplot(self): |
| 782 | """ |
| 783 | Ensures that pyplot has been imported into the embedded IPython shell. |
| 784 | |
| 785 | Also, makes sure to set the backend appropriately if not set already. |
| 786 | |
| 787 | """ |
| 788 | # We are here if the @figure pseudo decorator was used. Thus, it's |
| 789 | # possible that we could be here even if python_mplbackend were set to |
| 790 | # `None`. That's also strange and perhaps worthy of raising an |
| 791 | # exception, but for now, we just set the backend to 'agg'. |
| 792 | |
| 793 | if not self._pyplot_imported: |
| 794 | if 'matplotlib.backends' not in sys.modules: |
| 795 | # Then ipython_matplotlib was set to None but there was a |
| 796 | # call to the @figure decorator (and ipython_execlines did |
| 797 | # not set a backend). |
| 798 | #raise Exception("No backend was set, but @figure was used!") |
| 799 | import matplotlib |
| 800 | matplotlib.use('agg') |
| 801 | |
| 802 | # Always import pyplot into embedded shell. |
| 803 | self.process_input_line('import matplotlib.pyplot as plt', |
| 804 | store_history=False) |
| 805 | self._pyplot_imported = True |
| 806 | |
| 807 | def process_pure_python(self, content): |
| 808 | """ |
no test coverage detected