简体   繁体   English

Python 2.7.12 Matplotlib x11转发未显示或引发多个错误

[英]Python 2.7.12 Matplotlib x11 forwarding not showing or throwing multiple errors

I am logging in to a remote linux machine from windows 7 via putty. 我正在通过腻子从Windows 7登录到远程Linux机器。 In the settings I enabled the X11 forwarding option, and added the -X flag when loging in to the ssh server. 在设置中,我启用了X11转发选项,并在登录ssh服务器时添加了-X标志。 On this server I run the following python code: 在此服务器上,我运行以下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

I get all the print values, with the output looking like this: 我得到了所有的打印值,输出看起来像这样:

(300, 512, 512)
3
4

there is no error raised nor a x11 window opend. 没有引发错误,也没有打开x11窗口。 The comadoline goes back as if the program was at the end. comadoline返回,好像程序结束了一样。 Is there any possibility to get the plt.show() comand to actually show on the remote controlling windows machine? 是否有可能让plt.show()命令实际显示在远程控制Windows机器上?

I got it figured out: 我明白了:

at first it is like "tcaswell" said, you can´t use the 'Agg' backend with interactive windows. 首先,就像“ tcaswell”说的那样,您不能将'Agg'后端与交互式窗口一起使用。 This error gets fixed by just deleting the first two lines of code. 仅删除前两行代码即可解决此错误。 The second problem is, that by the plt.figure(1) comand a new figure 1 is created but in the plt.show() comand there is no figure specified that should show up. 第二个问题是,通过plt.figure(1)创建了新的图形1,但是在plt.show()中没有指定应显示的图形。 So this error can be solved by either deleting the line that says plt.figure(1) or by putting the number of the figure to plot in the brackets behind the plt.show() comand: plt.show(1) . 因此,可以通过删除表示plt.figure(1)或将要绘制的图形编号放在plt.show()后面的方括号内来解决此错误: plt.show(1) By this way it is possible to create multiple figures in one file and being able to switch between them. 通过这种方式,可以在一个文件中创建多个图形并能够在它们之间切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM