尽管我调用了 pyplot.show(),但 matplotlib 没有显示我的绘图 [英] matplotlib does not show my drawings although I call pyplot.show()

查看:36
本文介绍了尽管我调用了 pyplot.show(),但 matplotlib 没有显示我的绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要有关 matplotlib 的帮助.是的,我没有忘记调用 pyplot.show().

$ ipython --pylab

import matplotlib.pyplot as pp.plot(范围(20),范围(20))

它返回 matplotlib.lines.Line2D at 0xade2b2c 作为输出.

p.show()

没有什么可发生的.没有错误信息.没有新窗口.没有什么.我使用 pip 安装 matplotlib 并且我没有收到任何错误消息.

详情:

我用,

  • Ubuntu
  • IPython v0.11
  • Python v2.6.6
  • matplotlib v1.0.1

解决方案

如果我在 ~/.matplotlib/matplotlibrc 中将我的后端设置为 template,然后我可以重现你的症状:

~/.matplotlib/matplotlibrc:

# 后端:GtkAgg后端:模板

请注意,文件 matplotlibrc 可能不在目录 ~/.matplotlib/ 中.在这种情况下,以下代码显示了它的位置:

<预><代码>>>>导入 matplotlib>>>matplotlib.matplotlib_fname()

<小时>

In [1]: import matplotlib.pyplot as p在 [2]: p.plot(range(20),range(20))输出 [2]:[]在 [3] 中:p.show()

<小时>

如果您编辑 ~/.matplotlib/matplotlibrc 并将后端更改为类似 GtkAgg 的内容,您应该会看到一个情节.您可以使用

列出您机器上可用的所有后端

导入 matplotlib.rcsetup 作为 rcsetup打印(rcsetup.all_backends)

它应该返回一个列表,如:

['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'MacOSX', 'QtAgg', 'Qt4Agg','TkAgg', 'WX', 'WXAgg', 'CocoaAgg', 'agg', 'cairo', 'emf', 'gdk', 'pdf','ps'、'svg'、'模板']

参考:

Help required on matplotlib. Yes, I did not forget calling the pyplot.show().

$ ipython --pylab

import matplotlib.pyplot as p 
p.plot(range(20), range(20))

It returns matplotlib.lines.Line2D at 0xade2b2c as the output.

p.show()

There is nothing to happen. No error message. No new window. Nothing. I install matplotlib by using pip and I didn't take any error messages.

Details:

I use,

  • Ubuntu
  • IPython v0.11
  • Python v2.6.6
  • matplotlib v1.0.1

解决方案

If I set my backend to template in ~/.matplotlib/matplotlibrc, then I can reproduce your symptoms:

~/.matplotlib/matplotlibrc:

# backend      : GtkAgg
backend      : template

Note that the file matplotlibrc may not be in directory ~/.matplotlib/. In this case, the following code shows where it is:

>>> import matplotlib
>>> matplotlib.matplotlib_fname()


In [1]: import matplotlib.pyplot as p

In [2]: p.plot(range(20),range(20))
Out[2]: [<matplotlib.lines.Line2D object at 0xa64932c>]

In [3]: p.show()


If you edit ~/.matplotlib/matplotlibrc and change the backend to something like GtkAgg, you should see a plot. You can list all the backends available on your machine with

import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)

It should return a list like:

['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'MacOSX', 'QtAgg', 'Qt4Agg',
'TkAgg', 'WX', 'WXAgg', 'CocoaAgg', 'agg', 'cairo', 'emf', 'gdk', 'pdf',
'ps', 'svg', 'template']

Reference:

这篇关于尽管我调用了 pyplot.show(),但 matplotlib 没有显示我的绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆