最近在调研用Faster RCNN做object detection,发现桌面环境下matplotlib不能显示图像。
(实验室的开发环境:Centos6.5+Python2.7,使用VNC远程连接图形桌面。)
首先在stackoverflow上看到了一个帖子:https://stackoverflow.com/questions/7534453/matplotlib-does-not-show-my-drawings-although-i-call-pyplot-show
了解到这种情况可能跟matplotlib的后端有关。
In [1]: import matplotlib
In [2]: matplotlib.get_backend()
Out[2]: u'agg'
可以看到系统默认的后端是agg,
agg是不会画图的!
In [3]: matplotlib.matplotlib_fname()
Out[3]: u'/home/james/.config/matplotlib/matplotlibrc'
找到matplotlibrc的路径,将backend改为Qt4Agg。Qt4出了点问题,Google一下很容易解决了。
这下可以愉快地用pyplot.show()查看检测结果了~