How to make IPython notebook matplotlib plot inline

后端 未结 10 2263
轮回少年
轮回少年 2020-11-22 14:37

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 matplo         


        
10条回答
  •  执念已碎
    2020-11-22 15:05

    I had the same problem when I was running the plotting commands in separate cells in Jupyter:

    In [1]:  %matplotlib inline
             import matplotlib
             import matplotlib.pyplot as plt
             import numpy as np
    In [2]:  x = np.array([1, 3, 4])
             y = np.array([1, 5, 3])
    In [3]:  fig = plt.figure()
             
    #this might be the problem In [4]: ax = fig.add_subplot(1, 1, 1) In [5]: ax.scatter(x, y) Out[5]: # CAN'T SEE ANY PLOT :( In [6]: plt.show() # STILL CAN'T SEE IT :(

    The problem was solved by merging the plotting commands into a single cell:

    In [1]:  %matplotlib inline
             import matplotlib
             import matplotlib.pyplot as plt
             import numpy as np
    In [2]:  x = np.array([1, 3, 4])
             y = np.array([1, 5, 3])
    In [3]:  fig = plt.figure()
             ax = fig.add_subplot(1, 1, 1)
             ax.scatter(x, y)
    Out[3]:  
             # AND HERE APPEARS THE PLOT AS DESIRED :)
    

提交回复
热议问题