Python 相同的结果集imshow可以打印,而pcolormesh不能

Python 相同的结果集imshow可以打印,而pcolormesh不能,python,numpy,matplotlib,scipy,kde,Python,Numpy,Matplotlib,Scipy,Kde,我使用scipy.stats.kde.gaussian_kde()进行kde分析,处理大量点需要时间(对于具有250x250网格的100000点,需要5分钟) 作为高斯函数的一种更快的替代方法,我发现了由。(加权kde也是选择fast_kde的一个因素) 我不是绘制结果,而是将其以格式(xmin、xmax、ymin、ymax、value)提取到文件中供以后使用。我正在使用该技术通过使用提取原始形式的结果 以下是问题陈述: 由fast_kde函数为网格(500500)生成的结果不能由pcolorm

我使用scipy.stats.kde.gaussian_kde()进行kde分析,处理大量点需要时间(对于具有250x250网格的100000点,需要5分钟)

作为高斯函数的一种更快的替代方法,我发现了由。(加权kde也是选择fast_kde的一个因素)

我不是绘制结果,而是将其以格式(xmin、xmax、ymin、ymax、value)提取到文件中供以后使用。我正在使用该技术通过使用提取原始形式的结果

以下是问题陈述: 由fast_kde函数为网格(500500)生成的结果不能由pcolormesh绘制,原始形式的输出也反映了相同的无效结果,但imshow方法完美地绘制了该结果

生成一些随机二维数据:

from scipy import stats
def measure(n):
    "Measurement model, return two coupled measurements."
    m1 = np.random.normal(size=n)
    m2 = np.random.normal(scale=0.5, size=n)
    return m1+m2, m1-m2
m1, m2 = measure(2000)
xmin = m1.min()
xmax = m1.max()
ymin = m2.min()
ymax = m2.max()
对数据执行内核密度估计:

X, Y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
positions = np.vstack([X.ravel(), Y.ravel()])
values = np.vstack([m1, m2])
kernel = stats.gaussian_kde(values)
Z = np.reshape(kernel(positions).T, X.shape)
将结果保存到文件:(x、y、值)

打印结果:(minx、maxx、miny、maxy、value)

绘制结果:

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(np.rot90(Z), cmap=plt.cm.gist_earth_r,
          extent=[xmin, xmax, ymin, ymax])
ax.plot(m1, m2, 'k.', markersize=2)
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
plt.show()
用于fast_kde的代码(问题区域


请建议我如何在这里添加图像(在哪里上传?

请发布一些示例代码。这是一个问题。为了清楚起见,我将其添加到问题中。您能将其减少到演示您的问题所需的最低限度吗?任何照片共享网站都可以使用(谷歌、imgur等)
mshgrd = ax.pcolormesh(X,Y,Z) 
pths = mshgrd.get_paths() 
arr = mshgrd.get_array() 
for currentIndex,elem in enumerate(pths): 
 if arr[currentIndex]>0: bbox = elem.get_extents() 
 s2 = ",".join([str(i) for i in bbox.extents])+","+ str(arr[currentIndex]) +'\n' 
 print s2
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(np.rot90(Z), cmap=plt.cm.gist_earth_r,
          extent=[xmin, xmax, ymin, ymax])
ax.plot(m1, m2, 'k.', markersize=2)
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
plt.show()
kernel = fast_kde(m1,m2,(500,500))
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
mshgrd = ax.pcolormesh(X,Y,kernel)
plt.show()