【问题标题】:IPython plotting inline not showingIPython内联绘图未显示
【发布时间】:2013-10-22 21:13:51
【问题描述】:

我在 Linux 上运行 IPython QT 控制台的 IPython 中有以下代码。

%pylab inline

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

fig = figure()

ax = fig.add_axes()

ax = fig.add_axes([0,500, 0, 5000])

ax.plot([1,2,3,44], [4,4,55,55])
Out[5]: [<matplotlib.lines.Line2D at 0x3d8e7d0>]

fig
Out[6]: <matplotlib.figure.Figure at 0x3d25fd0>

fig.show()
/usr/lib/pymodules/python2.7/matplotlib/figure.py:362: UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure
  "matplotlib is currently using a non-GUI backend, "

一段时间以来,我一直在努力完成这项工作,我尝试使用 matplotlib.use() 手动将后端更改为 Qt4AggGTK 等,但没有成功。即使我打电话给display()IPython notebook 也会发生这种情况。

任何想法如何让内联绘图工作?


将 Jakob 的答案标记为答案,但实际上两者都是正确的。我必须用新副本替换 matploblibrc 文件,使用 --pylab=None 启动 IPython QT 控制台,然后在控制台中手动输入 %pylab inline。不知何故,这解决了问题。

【问题讨论】:

  • 如果您不是专家,并且害怕从源代码构建,您可以尝试从软件存储库安装,即 apt-get、yum 等

标签: matplotlib ipython


【解决方案1】:

轴对象定义不正确,这会阻止 matplotlib 渲染。
删除第一行ax = fig.add_axes(),并将第二行替换为
ax = fig.add_axes([0, 0, 1, 1])

add_axes 方法以 relative 坐标请求轴的大小,格式为 left,bottom,width,height,值在 0 和 1 之间,参见例如matplotlib tutorial.

您也可以尝试使用fig.add_subplot(111) 而不是fig.add_axes()fig,ax = subplots() 来创建您的图形和轴对象。后者假定您已在 IPython 中填充了交互式命名空间 matplotlib (%pylab) 调用。

【讨论】:

    【解决方案2】:

    看起来你的 matplotlib 构建是在没有 gui 后端的情况下编译的。

    当 a) 明确指定(对 web 服务器很方便)或 b) 至少一个 gui 后端所需的库不存在时(例如,没有 TkGtkQt、等)。

    你是如何安装 matplotlib 的?

    如果您是从源代码编译它,请确保您至少安装了 Tk 的开发库,并且您的 python 安装是使用 Tk 支持编译的(默认情况下)。如果您从发行版的存储库安装它,那么构建该软件包的人在没有 gui 支持的情况下构建了它,您需要从其他来源安装它。

    【讨论】:

    • 我有 Spyder(使用 Anaconda)。如何将 Plot 本身作为一个窗口?
    猜你喜欢
    • 2015-05-04
    • 2015-04-07
    • 2017-02-22
    • 2013-11-09
    • 1970-01-01
    • 2013-03-06
    • 2013-10-24
    • 2015-03-01
    相关资源
    最近更新 更多