简体   繁体   English

IPython笔记本不会显示图

[英]IPython notebook won't show plot

Not sure why this simple plot won't show. 不知道为什么这个简单的图不会显示。 simply shows an In[*] and won't finish loading the plot. 只是显示一个In [*]而不会完成加载绘图。 Can't find any info on what the * means. 找不到有关*含义的任何信息。 Any help? 有什么帮助吗?

import numpy as np
import matplotlib.pyplot as plt


r = np.arange(1,11)
v2 = 1.0/r

font = {'family' : 'serif',
    'color'  : 'black',
    'weight' : 'normal',
    'size'   : 18,
    }
plt.xlabel('$V*$', fontdict = font)
plt.ylabel('$Radii$', fontdict = font)
plt.plot(r,v2,lw=2)
plt.show()

Setting the iPython notebook %matplotlib magic command here is what you need to display the plot. 在此处设置iPython笔记本%matplotlib magic命令是显示图所需要的。

Basically, that command tells the notebook which backend to use when plotting with matplotlib , and sets it to work interactively. 基本上,该命令告诉笔记本使用matplotlib进行绘图时要使用哪个后端,并将其设置为可交互工作。 You usually will want to set that at the top of your notebook. 通常,您希望将其设置在笔记本的顶部。

There are several options. 有几种选择。 A common one is 一个常见的是

%matplotlib inline

which displays the plots right there in the iPython notebook. 它在iPython笔记本中显示绘图。

Other options will depend on your system, but can include: 其他选项取决于您的系统,但可以包括:

‘gtk’, ‘gtk3’, ‘inline’, ‘nbagg’, ‘notebook’, ‘osx’, ‘qt’, ‘qt4’, ‘qt5’, ‘tk’, ‘wx’

If you just set: 如果您只是设置:

%matplotlib

without a gui option, it will use the default backend on your system (defined in your .matplotlibrc file). 如果没有gui选项,它将使用系统上的默认后端(在.matplotlibrc文件中定义)。

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

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