我遵循Imagegrid上matplotlib文档中的一个示例,并尝试从Jupyter notebook中复制它:
% matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np
im = np.arange(100)
im.shape = 10, 10
fig = plt.figure(1, (4., 4.))
grid = ImageGrid(fig, 111, # similar to subplot(111)
nrows_ncols=(2, 2), # creates 2x2 grid of axes
axes_pad=0.1, # pad between axes in inch.
)
for i in range(4):
grid[i].imshow(im) # The AxesGrid object work as a list of axes.
plt.show()
预期产量:
我得到的是:
我没有得到图像的网格,如你所见。我做错什么了?在
编辑
如果我删除%matplotlib inline
选项,我就得到这个(它是cell[1]
来证明我重新启动了内核):
未显示绘图。在
我正在运行matplotlib
版本3.0.0
,用conda list matplotlib
检查,jupyter
是{
这是一个issue with matplotlib 3.0.0。这现在是been fixed,因此它不会出现在即将到来的3.0.1错误修复版本中。在
同时你有两个选择。在
决定在使用
%matplotlib inline
时不裁剪图像。请通过在IPython或Jupyter。
删除
然后重新启动一切或者把它放在一个单独的牢房里,如下所示。magic命令似乎总是需要在绘图之前在单独的单元中运行,如果它是在需要重新启动内核之前运行的。看这里 enter link description here
它会起作用的。%matplotlib inline不需要在jupyter中呈现绘图,这只是一种方便。表演()将在调用时呈现绘图。在
我在jupyter遇到过这个问题。我认为问题在于,magic命令会使它在任何绘图可用时立即呈现,而mpl则会等待,直到被告知要渲染以及如何渲染。在
完整的示例代码来自您在问题中链接的mpl示例:
^{pr2}$相关问题 更多 >
编程相关推荐