尽管我调用pyplot.show(),但matplotlib不会显示我的绘图 [英] matplotlib does not show my drawings although I call pyplot.show()
问题描述
在matplotlib上需要帮助.是的,我没有忘记调用pyplot.show().
Help required on matplotlib. Yes, I did not forget calling the pyplot.show().
import matplotlib.pyplot as p
p.plot(range(20), range(20))
它返回matplotlib.lines.Line2D at 0xade2b2c
作为输出.
p.show()
没有任何反应.没有错误讯息.没有新窗口.没有.我通过使用pip安装matplotlib
,但没有收到任何错误消息.
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.
详细信息:
我用
- Ubuntu
- IPython v0.11
- Python v2.6.6
- matplotlib v1.0.1
推荐答案
如果我在~/.matplotlib/matplotlibrc
中将后端设置为template
,
然后我可以重现您的症状:
If I set my backend to template
in ~/.matplotlib/matplotlibrc
,
then I can reproduce your symptoms:
〜/.matplotlib/matplotlibrc:
~/.matplotlib/matplotlibrc:
# backend : GtkAgg
backend : template
请注意,文件matplotlibrc
可能不在目录~/.matplotlib/
中.在这种情况下,以下代码显示了它的位置:
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()
如果您编辑~/.matplotlib/matplotlibrc
并将后端更改为类似GtkAgg
的内容,则应该会看到一个图.您可以使用
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)
它应该返回如下列表:
['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'MacOSX', 'QtAgg', 'Qt4Agg',
'TkAgg', 'WX', 'WXAgg', 'CocoaAgg', 'agg', 'cairo', 'emf', 'gdk', 'pdf',
'ps', 'svg', 'template']
参考:
这篇关于尽管我调用pyplot.show(),但matplotlib不会显示我的绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!