別の関数によって呼び出され、いくつかの計算を実行し、出力をファイルにプロットするコードがあります。大規模なデータセットの場合、スクリプト全体を実行するには時間がかかる場合があるため、特定の時間に複数のデータセットを分析する必要がある場合があるため、スクリプトを開始してscreen
切断し、パテ セッションを閉じて、翌日にもう一度確認します。Ubuntu 14.04 を使用しています。私のコードは次のようになります(計算をスキップしました):
import shelve
import os, sys, time
import numpy
import timeit
import logging
import csv
import itertools
import graph_tool.all as gt
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.ioff()
#Do some calculations
print 'plotting indeg'
# Let's plot its in-degree distribution
in_hist = gt.vertex_hist(g, "in")
y = in_hist[0]
err = numpy.sqrt(in_hist[0])
err[err >= y] = y[err >= y] - 1e-2
plt.figure(figsize=(6,4))
plt.errorbar(in_hist[1][:-1], in_hist[0], fmt="o",
label="in")
plt.gca().set_yscale("log")
plt.gca().set_xscale("log")
plt.gca().set_ylim(0.8, 1e5)
plt.gca().set_xlim(0.8, 1e3)
plt.subplots_adjust(left=0.2, bottom=0.2)
plt.xlabel("$k_{in}$")
plt.ylabel("$NP(k_{in})$")
plt.tight_layout()
plt.savefig("in-deg-dist.png")
plt.close()
print 'plotting outdeg'
#Do some more stuff
プロット コマンドに到達するまで、スクリプトは問題なく実行されます。問題の根本にたどり着くために、現在、画面なしで X11 アプリケーションなしでパテで実行しています。私が得る出力は次のとおりです。
plotting indeg
PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused
: cannot connect to X server localhost:10.0
これは、コードがウィンドウを開こうとしていることが原因だと思いますが、明示的に設定plt.off()
することで無効になると思いました。そうではなかったので、このスレッド ( X サーバーを実行せずに matplotlib グラフを生成する) に従い、バックエンドを指定しましたが、それでも問題は解決しませんでした。どこが間違っているのでしょうか?