imshow和histogram2d:无法让他们工作

sky*_*tux 6 python numpy matplotlib

我正在学习Python,这是我的第一个问题.我已经阅读了与imshow的使用相关的其他主题,但没有找到任何有用的东西.对不起,我的英语不好.

我在这里绘制了一组点,左图:

点(左)和图像(右)

现在我想看一个点密度的图像,所以我使用了imshowhistogram2d,我在上一个链接中得到了右边的图像.

图像与点的分布不对应.这怎么可能?我已按照帮助中的说明进行操作,甚至更改了一些参数,但没有任何效果:(

代码是:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

j, h, k = np.loadtxt("test.dat", usecols=(2, 4, 6), \
    unpack=True)

# límites
xmin = -0.5
xmax =  3.0
ymin = -0.5
ymax =  4.0

# colores
j_h = j - h
h_k = h - k

# no todas las estrellas son graficadas    
x1 = 0.5
y1 = 0.5
b  = 2.2
c  = y1 - b * x1

x = y = np.array([])

for xi, yi in zip(h_k, j_h):
    if xi < (yi - c) / b:
        x = np.append(x, xi)
        y = np.append(y, yi)

# gráfico
fig = plt.figure(figsize=(8, 7))

ax = fig.add_subplot(111)
#ax.plot(x, y, "go")
ax.set_xlabel(r"X", fontsize=14)
ax.set_ylabel(r"Y", fontsize=14)
ax.axis([xmin, xmax, ymin, ymax])

# imagen
rango = [[xmin, xmax], [ymin, ymax]]
binsx = int((xmax - xmin) / 0.05)
binsy = int((ymax - ymin) / 0.05)
binsxy = [binsx, binsy]

H, xedges, yedges = np.histogram2d(x, y, range=rango, bins=binsxy)

extent = [yedges[0], yedges[-1], xedges[0], xedges[-1]]
cp = ax.imshow(H, interpolation='bilinear', extent=extent, cmap=cm.jet)
fig.colorbar(cp)

plt.show()
Run Code Online (Sandbox Code Playgroud)

所用数据的链接如下:

https://dl.dropbox.com/u/10411539/python/test.dat

任何帮助表示赞赏!

Ori*_*eto 5

尝试不同的插值,并转置矩阵以使其在同一轴上:

cp = ax.imshow(H.transpose()[::-1], interpolation='nearest', extent=extent, cmap=cm.jet)
Run Code Online (Sandbox Code Playgroud)