Python matplotlib/pyplot未打印特定.txt文件中的数据
我通过numpy的savetxt函数保存数据,并将其提取到绘图中。当我绘制它时,脚本执行时没有错误,但不显示曲线——只显示空窗口。这很奇怪,因为:Python matplotlib/pyplot未打印特定.txt文件中的数据,python,numpy,matplotlib,plot,Python,Numpy,Matplotlib,Plot,我通过numpy的savetxt函数保存数据,并将其提取到绘图中。当我绘制它时,脚本执行时没有错误,但不显示曲线——只显示空窗口。这很奇怪,因为: 当我从另一个文件(也使用savetxt保存)导入.txt数据时,相同的脚本会生成一个精细的绘图 如果我在脚本中创建数据点,例如使用arange,它会打印 .txt数据正在加载--我已将其打印到屏幕上 我检查了我的后端,它是TkAgg,互联网同意它应该是 我的代码是 # this script makes the plots of the eigen
# 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()
好吧,再深入一点,问题就被发现了。脚本正在打印,但打印的缩放效果太差,以至于它们被边界上的粗线遮挡。所以问题是用户错误
这就是为什么工程师不应该尝试成为艺术家 好吧,再挖一点,问题就被发现了。脚本正在打印,但打印的缩放效果太差,以至于它们被边界上的粗线遮挡。所以问题是用户错误
这就是为什么工程师不应该尝试成为艺术家 打印要打印的数据,以确保正确读取数据。数据由3333 x 2矩阵组成,因此此方法不可行。我已经绘制了大小相似的数据,但没有问题。您不必打印所有数据。看一看,比如说,你试图绘制的前三点和最后三点。同时检查
profile1.shape
,profile1.dtype
,profile1.max()
,profile1.min()
。确定。在这种情况下,是的,我已经运行了这些简单的测试,一切都正常。我还“手工”创建了一些数据,以.txt格式保存在目录中,并毫无问题地打印出来,比如说,profile1.shape
和profile1.dtype
?打印您试图打印的数据,以确保正确读取数据。数据由3333 x 2矩阵组成,因此这种方法不可行。我已经绘制了大小相似的数据,但没有问题。您不必打印所有数据。看一看,比如说,你试图绘制的前三点和最后三点。同时检查profile1.shape
,profile1.dtype
,profile1.max()
,profile1.min()
。确定。在这种情况下,是的,我已经运行了这些简单的测试,一切都正常。我还“手工”创建了一些数据,以.txt格式保存在目录中,并毫无问题地打印出来,比如说,profile1.shape
和profile1.dtype
?