简体   繁体   English

Jupyter Notebook-Matplotlib继续运行

[英]Jupyter Notebook - Matplotlib keep running

I just started to use Jupiter Notebook to learn Python . 我刚刚开始使用Jupiter Notebook学习Python while I am trying out matplotlib with this basic code: 当我用以下基本代码尝试matplotlib时:

import numpy as np
import matplotlib.pyplot as plt

plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

The kernel just keep running and nothing happen. 内核只是继续运行,什么也没有发生。 How to resolve this? 如何解决呢? Is there an dependency issue? 有依赖性问题吗? My newly installed matplotlib is 1.5.1, python is 3.5.2, numpy is 1.11. 我新安装的matplotlib是1.5.1, python是3.5.2, numpy是1.11。 Running on MacBook Pro 10.11(El Capitan). 在MacBook Pro 10.11(El Capitan)上运行。

To Visualize the plots created by the matplotlib in Jupiter Notebook or ipython notebook you have add one extra line at the beginning. 要在Jupiter Notebook或ipython Notebook中可视化由matplotlib创建的图,请在开始处添加一行。

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

If your matplotlib version is above 1.4, and you are using IPython 3.x you have to use the below code. 如果您的matplotlib 版本高于1.4,并且您正在使用IPython 3.x ,则必须使用以下代码。

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

It likely showed you a Matplotlib popup, with the IP(y) logo. 它可能会向您显示一个带有IP(y)徽标的Matplotlib弹出窗口。 To show it inline you have to use some IPython magic. 要内联显示它,您必须使用一些IPython魔术。 Run this in a cell somewhere: 在某个位置的单元格中运行此命令:

%matplotlib inline

After you close the popup it will finish the statement in your kernel 关闭弹出窗口后,它将在内核中完成该语句

It sometimes takes time until the kernel starts. 有时需要一段时间才能启动内核。

Check that the code is color-highlighted. 检查代码是否突出显示颜色。 If it is, it means that the kernel is running. 如果是,则表示内核正在运行。 Evaluate the cell again. 再次评估单元格。 You will notice a * beside that cell, meaning it's running. 您会在该单元格旁边看到一个* ,表示它正在运行。

And one more thing: Sometimes the plot is displayed but its window hides behind the notebook... Access it from the task bar 还有一件事:有时会显示绘图,但其窗口隐藏在笔记本后面...从任务栏访问它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM