code: def ensure_pyplot(self):
          
          # We are here if the @figure pseudo decorator was used. Thus, it's
          # possible that we could be here even if python_mplbackend were set to
          # `None`. That's also strange and perhaps worthy of raising an
          # exception, but for now, we just set the backend to 'agg'.
  
          if not self._pyplot_imported:
              if 'matplotlib.backends' not in sys.modules:
                  # Then ipython_matplotlib was set to None but there was a
                  # call to the @figure decorator (and ipython_execlines did
                  # not set a backend).
                  #raise Exception("No backend was set, but @figure was used!")
                  import matplotlib
                  matplotlib.use('agg')
  
              # Always import pyplot into embedded shell.
              self.process_input_line('import matplotlib.pyplot as plt',
                                      store_history=False)
              self._pyplot_imported = True
docs: Ensures that pyplot has been imported into the embedded IPython shell.
  
          Also, makes sure to set the backend appropriately if not set already.