【问题标题】:matplotlib plots do not show on Anaconda for Linuxmatplotlib 图不显示在 Anaconda for Linux 上
【发布时间】:2014-05-25 19:46:32
【问题描述】:

我已经阅读了这些并尝试了解决方案,但仍然没有得到任何显示:

matplotlib show nothing although i called show

Why doesn't pyplot.show() work? [duplicate]

matplotlib does not show my drawings although I call pyplot.show()

我在 Ubuntu 12.04 上使用 Python 2.7.6 |Anaconda 1.9.0(64 位)。 我该如何诊断问题并尝试解决它?

编辑:

-首先我编辑了matplotlibrc并将后端更改为GtkAgg(设置为QtAgg)。

-然后我尝试通过代码更改后端:matplotlib.rcParams['backend'] = "GtkAgg"

EDIT2 - 从 Spyder 控制台添加细节(最后没有显示图):

Python 2.7.6 |Anaconda 1.9.0 (64-bit)| (default, Jan 17 2014, 10:13:17) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Imported NumPy 1.8.0, SciPy 0.13.3, Matplotlib 1.3.1
Type "scientific" for more details.
>>> scientific

This is a standard Python interpreter with preloaded tools for scientific 
computing and visualization. It tries to import the following modules:

>>> import numpy as np  # NumPy (multidimensional arrays, linear algebra, ...)
>>> import scipy as sp  # SciPy (signal and image processing library)
>>> import matplotlib as mpl         # Matplotlib (2D/3D plotting library)
>>> import matplotlib.pyplot as plt  # Matplotlib's pyplot: MATLAB-like syntax
>>> from pylab import *              # Matplotlib's pylab interface
>>> ion()                            # Turned on Matplotlib's interactive mode

Within Spyder, this interpreter also provides:
    * special commands (e.g. %ls, %pwd, %clear)
    * system commands, i.e. all commands starting with '!' are subprocessed
      (e.g. !dir on Windows or !ls on Linux, and so on)

>>> plot(range(3))
[<matplotlib.lines.Line2D object at 0x3f3cd50>]
>>> show()

【问题讨论】:

  • 你到底尝试了什么?什么后端等等?
  • 什么平台?你在尝试 IPython 笔记本吗?您收到任何错误消息吗?
  • 我在 Ubuntu 12.04 上使用 Anaconda 1.9.0。我在 W7 机器上使用相同的 Anaconda,绘图工作得很好。不尝试使用 IPython。需要 Spyder 的绘图。
  • 你安装了 pygtk 吗?
  • 不熟悉。除非它与 Anaconda 一起提供,否则我不会拥有它。

标签: python-2.7 matplotlib ubuntu-12.04


【解决方案1】:

我最终通过在 Spyder 中执行此操作来解决: Preferences -> Console -> External modules -> check Install Spyder's input hook for Qt

【讨论】:

  • 我遇到了同样的问题。一旦我在 conda 环境中通过 Spyder 运行并绘制了任何东西,我就可以在 pycharm 中绘制问题所在的位置。神奇的事情与否我们永远不会知道......恭喜!
【解决方案2】:

为了使您的matplotlib 后端选择起作用,您需要为该后端安装 Python 绑定。例如,您可能正在运行像 GNOME 这样的基于 GTK 的窗口管理器,但仍然没有 Python 绑定。根据this,正确的Ubuntu 软件包是python-gtk。所以,打开你最喜欢的终端模拟器并进入

sudo apt-get install python-gtk

(您需要管理员权限才能执行此操作)。重新启动您的 python/matplotlib 会话,您应该一切顺利。

【讨论】:

  • 当我在终端中运行该代码时出现此错误:正在读取包列表...完成构建依赖关系树正在读取状态信息...完成 E:无法找到包 python-gtk
【解决方案3】:

我在 Mavericks,通过在 matplotlibrc 中将后端更改为 Qt4Agg 解决了这个问题。 (按照此处另一个答案的说明:Why doesn't pyplot.show() work?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-28
    • 2020-12-09
    • 2017-07-27
    • 2023-03-30
    • 2019-12-21
    • 1970-01-01
    • 2016-11-26
    • 2016-12-30
    相关资源
    最近更新 更多