2016-10-16 32 views
1

我通過numpy的savetxt函數保存了數據,並將其提取到繪圖。當我繪製腳本時,腳本無誤地執行,但不顯示曲線 - 只有空的窗口。這很奇怪,因爲:matplotlib/pyplot不繪製特定.txt文件中的數據

  1. 相同的腳本讓我從另一個文件導入.TXT數據的精細圖(使用savetxt還保存)。

  2. 如果我在腳本內創建了數據點,例如與arange,它陰謀。

  3. .txt數據正在加載 - 我已將它打印到屏幕上。

  4. 我檢查了我的後端,它是TkAgg,互聯網認爲它應該是。

我的代碼是

# this script makes the plots of the eigenvalue distributions for the AAS 17-225 paper 

# import python modules 
import numpy as np 
import matplotlib as mpl 
import matplotlib.pyplot as plt 
from matplotlib.ticker import MaxNLocator 

# set plot options 
mpl.rcParams['xtick.major.size'] = 7 
mpl.rcParams['xtick.major.width'] = 3.0 
mpl.rcParams['ytick.major.size'] = 7 
mpl.rcParams['ytick.major.width'] = 3.0 
mpl.rcParams['axes.linewidth'] = 3.5 

plt.rc('text',usetex=True) 
mpl.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"] 
plt.rc('font',family='serif') 
plt.rc('axes',labelsize=24) 
plt.rc('xtick',labelsize=24) 
plt.rc('ytick',labelsize=24) 
plt.rc('font',weight='bold') 
plt.rc('axes',titlesize=20) 

# plot method arguments 
lw = 2 # linewidth 
left_adj = 0.055 # left adjustment 
right_adj = 0.985 # left adjustment 
top_adj = 0.975 # left adjustment 
bottom_adj = 0.075 # left adjustment 
wspace = 0.205 # horizontal space between plots 
hspace = 0.2 # verticle space between plots 
n_suplot_rows = 2 # number of subplot rows 
n_suplot_columns = 3 # number of subplot columns 

# load data 
dataDir ='/mnt/E0BA55A7BA557B4C/research/independent/recursivequats/paperCode/' 
df1 = dataDir+'lamda_0p1_0p1.txt' 
df2 = dataDir+'lamda_0.1_0.5.txt' 
df3 = dataDir+'lamda_0.1_1.0.txt' 
df4 = dataDir+'lamda_0.5_0.5.txt' 
df5 = dataDir+'lamda_0.5_1.0.txt' 
df6 = dataDir+'lamda_1.0_1.0.txt' 

profile1 = np.loadtxt(df1) 
profile2 = np.loadtxt(df2) 
profile3 = np.loadtxt(df3) 
profile4 = np.loadtxt(df4) 
profile5 = np.loadtxt(df5) 
profile6 = np.loadtxt(df6) 

fig = plt.figure() 

ax1 = fig.add_subplot(n_suplot_rows,n_suplot_columns,1) 
p1, = ax1.plot(profile1[:,1],profile1[:,0],linewidth=lw) 

ax2 = fig.add_subplot(n_suplot_rows,n_suplot_columns,2) 
p1, = ax2.plot(profile2[:,1],profile2[:,0],linewidth=lw) 

ax3 = fig.add_subplot(n_suplot_rows,n_suplot_columns,3) 
p1, = ax3.plot(profile3[:,1],profile3[:,0],linewidth=lw) 

ax4 = fig.add_subplot(n_suplot_rows,n_suplot_columns,4) 
p1, = ax4.plot(profile4[:,1],profile4[:,0],linewidth=lw) 

ax5 = fig.add_subplot(n_suplot_rows,n_suplot_columns,5) 
p1, = ax5.plot(profile5[:,1],profile5[:,0],linewidth=lw) 

ax6 = fig.add_subplot(n_suplot_rows,n_suplot_columns,6) 
p1, = ax5.plot(profile6[:,1],profile6[:,0],linewidth=lw) 


plt.subplots_adjust(left=left_adj,right=right_adj,top=top_adj,bottom=bottom_adj,wspace=wspace,hspace=hspace) 
plt.show() 
+0

打印您試圖繪製的數據以確保數據已被正確讀取。 –

+0

數據由3333 x 2矩陣組成,所以這種方法是不可行的。然而,我繪製了類似大小的數據,沒有問題。 – SZN

+0

您不必打印*全部*數據。看看你試圖繪製的前三點和最後三點。同時檢查'profile1.shape','profile1.dtype','profile1.max()','profile1.min()'。 –

回答

0

好,多一點挖等問題已經被確定。腳本繪圖,但圖上的縮放非常差,以至於它們被邊界上的粗線遮擋。所以這個問題是一個用戶錯誤。

這就是爲什麼工程師不應該試圖成爲藝術家......

相關問題