回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我试着用散点绘制一些数据。我的代码是</p>
<pre><code>import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from scipy.interpolate import griddata
data = np.loadtxt('file1.txt')
x = data[:,0]
y = data[:,1]
z = data[:,2]
plt.scatter(x, y, c=z, s=100, cmap=mpl.cm.spectral)
cbar=plt.colorbar()
s=18
plt.ylabel(r"$a_v$", size=s)
plt.xlabel(r"$a_{\rm min}$", size=s)
plt.xlim([x.min(),x.max()])
plt.ylim([y.min(),y.max()])
plt.show()
</code></pre>
<p>结果是
<img src="https://i.stack.imgur.com/DtJ6G.png" alt="enter image description here"/></p>
<p>现在我有了一个想法,想用一些数据来演示一下,因为我不喜欢散乱的圆圈。
所以我试过这个</p>
<pre><code>from matplotlib.mlab import griddata
import matplotlib.pyplot as plt
data = np.loadtxt('file1.txt')
x = data[:,0]
y = data[:,1]
z = data[:,2]
N = 30j
extent = (min(x), max(x), min(y), max(y))
xs,ys = np.mgrid[extent[0]:extent[1]:N, extent[2]:extent[3]:N]
resampled = griddata(x, y, z, xs, ys)
plt.imshow(resampled.T, extent=extent)
s=18
plt.ylabel(r"$a_v$", size=s)
plt.xlabel(r"$a_{\rm min}$", size=s)
plt.xlim([x.min(),x.max()])
plt.ylim([y.min(),y.max()])
cbar=plt.colorbar()
plt.show()
</code></pre>
<p>结果是:
<img src="https://i.stack.imgur.com/ubw3i.png" alt="enter image description here"/></p>
<p>我的问题显然是为什么<code>imshow()</code>要反转数据?这里到底发生了什么?</p>
<p>附:这是<a href="https://dl.dropbox.com/u/8189209/file1.txt" rel="noreferrer">data</a>,以防有人想和他们一起玩</p>