Python 我有一张银河系的照片,我只想画第500行

Python 我有一张银河系的照片,我只想画第500行,python,matplotlib,plot,Python,Matplotlib,Plot,这个文件是1000乘1000,我想打印所有的x值,但只打印数据的第500行。到目前为止,我的代码是: import matplotlib.pyplot as plt from numpy import * from pylab import * import scipy.ndimage from scipy import * data = fromfile("m33.dat",dtype=int16) data_fortran=data.reshape((1000,1000),order="F

这个文件是1000乘1000,我想打印所有的x值,但只打印数据的第500行。到目前为止,我的代码是:

import matplotlib.pyplot as plt
from numpy import *
from pylab import *
import scipy.ndimage
from scipy import *

data = fromfile("m33.dat",dtype=int16)
data_fortran=data.reshape((1000,1000),order="FORTRAN")
data2 = scipy.ndimage.filters.gaussian_filter(data_fortran,5,mode="nearest")

#plot m33.dat into a contour plot
plt.imshow(data2,interpolation="none",cmap="binary")
plt.show()

由于Python使用基于0的索引,第500行将位于索引值499处。

我尝试使用data2[499],它给了我TypeError:图像数据的维度无效我的错误。要使行成为二维的,可以使用
重塑(1,-1)
-1
被任何有意义的正整数替换。
plt.imshow(data2[499].reshape(1,-1),interpolation="none",cmap="binary")