python FITS文件绘图给出了不同的结果



我在运行脚本时遇到了一个问题(请找到下面的代码)。

我试图绘制值数组,将其写入FITS文件格式,再次读取并绘制它->我没有得到相同的图!

如果你能帮我一下,那就太好了。

以下是我的包和编译器的版本:

matplotlib: '2.0.0b1'

numpy: '1.11.0'

astropy: u'1.1.2'

python: 2.7

真诚,阿哈尔德

import numpy as np
from pylab import *
from astropy.io import fits
# Just making a 10x10 meshgrid
x = np.arange(10)
X , Y = np.meshgrid(x,x)
# finding the distance of different points on the meshgrid from a point suppose at (5,5)
Z = ((X-5)**2 + (Y-5)**2)**0.5 
# plotting Z (see image [link below] - left one)
imshow(Z, origin = "lower")
colorbar()
show()
# writing the Z data into a fits file
fits.writeto("my_file.fits", Z)
# reading the same fits file and storing the data
Z_read = fits.open("my_file.fits")[0].data
# plotting Z_read : we expect it to show the same plot as before
imshow(Z_read, origin = "lower")
colorbar()
show()
# Lo! That's not the case for me! It's not the same plot! (see image - right one)
# Hence, I try to check whether the values stored in Z and Z_read are different..
print Z - Z_read
# No! It returns an array full of zeros! This means Z and Z_read are the same! I don't get why the plots look different!

请在此链接中找到图像:https://i.stack.imgur.com/O6UQg.jpg

实际上这是与matplotlib的版本有关。

matplotlib开发人员的回答- Jens Nielsen

这在matplotlib 1.51版本中不会发生

在版本2 beta 1中,FITS数据似乎从float32转换为大端浮点float8。请看下面的链接:

https://gist.github.com/jenshnielsen/86d4a86d8f667fadddc09f88c5fb87e6

问题已经发布,你可以在这里查看:

https://github.com/matplotlib/matplotlib/issues/6671

在此期间,对于具有相同的绘图(Z和Z _read),我们应该使用以下代码(用于matplotlib 2 beta 1):
imshow(Z_read.astype('float64'), origin = "lower")

最新更新