MCPcopy Create free account
hub / github.com/ipython/ipython / ensure_pyplot

Method ensure_pyplot

IPython/sphinxext/ipython_directive.py:761–785  ·  view source on GitHub ↗

Ensures that pyplot has been imported into the embedded IPython shell. Also, makes sure to set the backend appropriately if not set already.

(self)

Source from the content-addressed store, hash-verified

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 """

Callers 2

save_imageMethod · 0.95
process_pure_pythonMethod · 0.95

Calls 1

process_input_lineMethod · 0.95

Tested by

no test coverage detected