QBoard » Advanced Visualizations » Viz - Python » How to make IPython notebook matplotlib plot inline

How to make IPython notebook matplotlib plot inline


  • I am trying to use IPython notebook on MacOS X with Python 2.7.2 and IPython 1.1.0.

    I cannot get matplotlib graphics to show up inline.

    import matplotlib
    import numpy as np
    import matplotlib.pyplot as plt
    %matplotlib inline ​

    I have also tried %pylab inline and the ipython command line arguments --pylab=inline but this makes no difference.

    x = np.linspace(0, 3*np.pi, 500)
    plt.plot(x, np.sin(x**2))
    plt.title('A simple chirp')
    plt.show()​

    Instead of inline graphics, I get this:

    <matplotlib.figure.Figure at 0x110b9c450>​

    And matplotlib.get_backend() shows that I have the 'module://IPython.kernel.zmq.pylab.backend_inline' backend.
      September 24, 2020 1:01 PM IST
    0
    • Laksh Nath
      Laksh Nath Use the %pylab inline magic command.
      September 24, 2020
  • I did the anaconda install but matplotlib is not plotting

    It starts plotting when i did this

    import matplotlib
    import numpy as np
    import matplotlib.pyplot as plt
    %matplotlib inline
      September 24, 2020 5:01 PM IST
    0
  • I used%matplotlib inline in the first cell of the notebook and it works. I think you should try:

    %matplotlib inline
    
    import matplotlib
    import numpy as np
    import matplotlib.pyplot as plt

    You can also always start all your IPython kernels in inline mode by default by setting the following config options in your config files:

    c.IPKernelApp.matplotlib=<CaselessStrEnum>
      Default: None
      Choices: ['auto', 'gtk', 'gtk3', 'inline', 'nbagg', 'notebook', 'osx', 'qt', 'qt4', 'qt5', 'tk', 'wx']
      Configure matplotlib for interactive use with the default matplotlib backend.
      September 24, 2020 5:03 PM IST
    0
  • If your matplotlib version is above 1.4, it is also possible to use

    IPython 3.x and above

    %matplotlib notebook
    
    import matplotlib.pyplot as plt

    older versions

    %matplotlib nbagg
    
    import matplotlib.pyplot as plt

    Both will activate the nbagg backend, which enables interactivity.


      September 24, 2020 5:04 PM IST
    0
  • Ctrl + Enter

    %matplotlib inline

    Magic Line :D

    See: Plotting with Matplotlib.

      September 24, 2020 5:05 PM IST
    0
  • To make matplotlib inline by default in Jupyter (IPython 3):

    Please note that adding this line to 

        Edit file ~/.ipython/profile_default/ipython_config.py
    
        Add line c.InteractiveShellApp.matplotlib = 'inline'

    ipython_notebook_config.py would not work. Otherwise it works well with Jupyter and IPython 3.1.0

      September 24, 2020 5:06 PM IST
    0