Python 2.7.12 Matplotlib x11 转发不显示或抛出多个错误
Python 2.7.12 Matplotlib x11 forwarding not showing or throwing multiple errors
我正在通过 putty 从 windows 7 登录远程 linux 机器。在设置中,我启用了 X11 转发选项,并在登录到 ssh 服务器时添加了 -X 标志。在此服务器上,我 运行 以下 python 代码:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import pyfits
a = raw_input("path: ") #filepath on the server, conected with filename
file = pyfits.open (a +'/file.fits', memap = 'True')
data = file[0].data
print data.shape #shape gets printed correctly
plt.figure(1)
plt.imshow(data[0,:,:], cmap = 'gray')
print 3
plt.show()
print 4
我得到了所有打印值,输出如下所示:
(300, 512, 512)
3
4
没有出现错误,也没有打开 x11 window。 comadoline 返回,就好像程序结束了一样。是否有可能让 plt.show()
命令实际显示在远程控制 windows 机器上?
我明白了:
起初就像 "tcaswell" 所说的那样,您不能将 'Agg'
后端与交互式 windows 一起使用。只需删除前两行代码即可修复此错误。
第二个问题是,通过 plt.figure(1)
命令创建了一个新图 1,但在 plt.show()
命令中没有指定应该显示的图。因此,可以通过删除 plt.figure(1)
行或将要绘制的图形编号放在 plt.show()
命令后面的括号中来解决此错误:plt.show(1)
。通过这种方式,可以在一个文件中创建多个图形并能够在它们之间切换。
我正在通过 putty 从 windows 7 登录远程 linux 机器。在设置中,我启用了 X11 转发选项,并在登录到 ssh 服务器时添加了 -X 标志。在此服务器上,我 运行 以下 python 代码:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import pyfits
a = raw_input("path: ") #filepath on the server, conected with filename
file = pyfits.open (a +'/file.fits', memap = 'True')
data = file[0].data
print data.shape #shape gets printed correctly
plt.figure(1)
plt.imshow(data[0,:,:], cmap = 'gray')
print 3
plt.show()
print 4
我得到了所有打印值,输出如下所示:
(300, 512, 512)
3
4
没有出现错误,也没有打开 x11 window。 comadoline 返回,就好像程序结束了一样。是否有可能让 plt.show()
命令实际显示在远程控制 windows 机器上?
我明白了:
起初就像 "tcaswell" 所说的那样,您不能将 'Agg'
后端与交互式 windows 一起使用。只需删除前两行代码即可修复此错误。
第二个问题是,通过 plt.figure(1)
命令创建了一个新图 1,但在 plt.show()
命令中没有指定应该显示的图。因此,可以通过删除 plt.figure(1)
行或将要绘制的图形编号放在 plt.show()
命令后面的括号中来解决此错误:plt.show(1)
。通过这种方式,可以在一个文件中创建多个图形并能够在它们之间切换。