我試圖在中央服務器上運行一個模擬(用python編寫),當模擬完成時,將保存的圖形文件/保存的數據文件移動到我的本地PC,連接到我的本地PC。代碼如下:tkinter.TclError:無法連接到顯示「localhost:18.0」
import matplotlib.pyplot as plt
import subprocess
import scipy.io
import os
#Save data file:
scipy.io.savemat(data_path + Filename_str, dict(A=board))
#Create/Save figure by using imshow (Heatmap)
p = plt.imshow(mean_map.T, cmap = plt.cm.gist_yarg_r, origin = 'lower', extent = [0, phi, 0, Z], aspect='auto')
plt.savefig(figure_path + Filename_str + '-Homophily.pdf')
# Connect to my local host (arabian-knights) using ssh, and follow command.
ret = subprocess.call(['ssh', 'arabian-knights', 'mv Data/* /scratch/Data/'])
ret = subprocess.call(['ssh', 'arabian-knights', 'mv Figure/* /scratch/Figure/'])
我運行這個模擬在服務器計算機的背景下,連接到服務器計算機從我的本地計算機(阿拉伯騎士)之後。即使我關閉與服務器計算機的連接,因爲模擬在後臺運行,但它不會停止,數據文件在模擬完成後會正確地移動到本地計算機。然而,圖文件(由生產matplotlib.pyplot.imshow)不會被保存,顯示以下錯誤訊息話題:
Traceback (most recent call last):
File "./ThrHomoHeatmap-thrstep.py", line 179, in <module>
p = plt.imshow(board.T, cmap = plt.cm.gist_yarg_r, vmin=0, vmax=n, origin = 'lower', extent = [0, phi, 0, Z], aspect='auto')
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2370, in imshow
ax = gca()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 701, in gca
ax = gcf().gca(**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 369, in gcf
return figure()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 343, in figure
**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 80, in new_figure_manager
window = Tk.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1688, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "localhost:18.0"
是否有任何人誰可以解決這個問題,從移動matplotlib.pyplot圖文件服務器到本地計算機呢?
相關:http://stackoverflow.com/questions/2801882/generating-a-png-with-matplotlib-when-display-is-undefined?lq=1 –