【问题标题】:matplotlib show nothing although i called showmatplotlib 什么都不显示,虽然我叫 show
【发布时间】:2013-07-04 03:14:27
【问题描述】:

我是matplotlib的新手。

最近我在 #Win-7 64bit# 上使用 #WinPython-64bit-3.3.2.1# 并且当我在 IPython Qt 控件上键入如下代码时:

In [1]: plot(range(3))    
Out[1]: [<.matplotlib.lines.Line2D at 0x64ae390>] 
% There is a plot. 
In [2]: show() 
%nothing happened.

演出后应该有剧情。但是什么也没发生,没有错误信息。 savefig() 只会保存一个空白无花果。 我通过设置 backends = 'GtkAgg' 或 'QtAgg' 尝试了matplotlib does not show my drawings although I call pyplot.show() 的解决方案,但没有成功。

感谢您的建议。 :)

更新数据1: 使用 'WinPython Interpreter.exe' 代替 'IPython QT Console.exe'。 然后我输入了相同的代码,show() 工作了。 后端设置为GtkAgg

我认为原因如下:

由于 WinPythonInterpreter 是一个命令窗口,它需要一个新窗口来显示绘图。 IPython 支持交互式数据可视化,不需要另一个窗口。

Updata2:我刚刚发现gcf() 在 QT 控制台中返回了不同的引用,并且它在 WinPython 解释器中返回了相同的引用。也许这就是问题所在。

【问题讨论】:

  • setting backends = 'GtkAgg' or 'QtAgg', but it did not work. 你有没有得到错误或只是一个空白的数字?您的默认后端是什么?
  • 你是在pylab模式下开始的吗?如果不使用--pylab 命令行开关,您可以尝试一下吗(在这种情况下,您不需要 show 语句,因为它是“交互式”的)
  • @FrancescoMontesano ,我在 matplotlibrc 文件中设置了后端,但没有任何改变。默认后端应为原始:GTKAgg
  • 如果你这样做plot(list(range(3)))会起作用吗?
  • 嗨,@mutzmatron,我在 Windows 上使用 WinPython,不确定它是否处于 pylab 模式。所以我在cmd中尝试了'IPython Console Qt --pylab',没有任何改变。

标签: matplotlib ipython


【解决方案1】:

WinPython IPython QT 控制台似乎默认为带有内联后端的 pylab,如 cmets 中建议的 mutzmatron。

知道 Matplotlib 在什么模式下工作可能会有点令人困惑,请参阅 Matplotlib pylab and pyplot: how they are related?

我倾向于使用 Python 发行版Anaconda,它的 QTConsole 默认不预加载 pylab,因此您可以导入 pyplot 并使用 show(),使用 WinPython,您可以通过转到 WinPython* 来启动 IPython QT 控制台。 \python*\Scripts 目录,带有 windows 命令提示符并启动 ipython3.exe qtconsole

import matplotlib.pyplot as plt
plt.plot(range(3))
plt.show()

虽然在绘图打开时会在 IPython QT 控制台中停止执行。您可以检测到 plt.get_backend() 正在使用哪个后端,Anaconda IPython QT 控制台在我的 Windows 7 安装中使用 QT4Agg

【讨论】:

  • @semuas,是的,WinPython IPython QT 控制台会预加载 pylab 和 matplotlib。但我不认为这是原因。也许 gcf() 返回不同的引用会导致这个问题。我将更新我的问题中的详细信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-17
  • 1970-01-01
  • 1970-01-01
  • 2021-11-08
  • 2016-12-08
  • 2018-10-05
  • 1970-01-01
相关资源
最近更新 更多