1

我有以下问题。我从事天体物理学,并试图制作一张天空图。收集到的数据告诉我每个 (x,y) 坐标处的天空温度。我一直在寻找如何绘制这个的问题,但到目前为止我想出的最好的方法是使用网格网格。然而,我的问题是,如果 Z 是 X 和 Y 的某个函数,这将完美地工作。这里不是这种情况;每个 (x,y) 组合只对应一个温度。我一直在尝试的(显然没有成功,需要测试一些“假数据”):

import numpy as np
import matplotlib.pyplot as plt

xw = [0,1,2,3,4,5]
yw = [20,30,40,50,60]
zw = [-10,-20,-30,-40,-50]

#Z=np.array((xw,yw,zw))
X,Y=np.meshgrid(xw,yw)
Z = X*Y
im = plt.pcolormesh(X,Y,Z, cmap='hot')
plt.colorbar(im, orientation='vertical')
plt.show()

.txt 文件中的输入格式:

x1 y1 T_11

x2 y1 T_21

x3 y1 T_31

...

xn y1 T_n1

x1 y2 T_12

x2 y2 T_22

x3 y2 T_32

等等

任何帮助将不胜感激:-)

4

1 回答 1

0
# make a dict of x-y coords mapping to z values
skymap = {}
for x,y,z in zip(xw,yw,zw):
    skymap[(x,y)] = z

# define a function of x and y that returns the corresponding z value
# (or some default - probably not 0, more like some function of nearest
# defined (x,y) neighbors)
def getZ(x,y):
    return skymap.get((x,y), 0)
于 2013-10-30T12:22:54.857 回答