<p>除了@jure关于设置<code>aspect</code>的回答(您可能还想尝试<code>equal</code>而不是<code>auto</code>,因为<code>auto</code>不能保证两个图看起来相同),您还需要确保两个子图之间的<code>xlim</code>和<code>ylim</code>是相同的,因为它现在看起来像是<code>x</code>和<code>y</code>范围在<code>imshow</code>中延伸得远远超出了散点图的范围。你知道吗</p>
<p>另外,在变换y和x坐标时,需要将范围设置为<code>-X, 0</code>和<code>-Y, 0</code></p>
<p>试试这个:</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
import matplotlib.image as img
import matplotlib.cm as cm
fig = plt.figure(figsize=(16, 8))
# here I am drawing a greyscale image
image = img.imread(filename)
ax1=fig.add_subplot(1, 2, 1, aspect='equal')
ax1.imshow(image, cmap=cm.Greys_r)
fig.tight_layout()
plt.axis('off')
# and here I am drawing a scatterplot based on this image.
X, Y = image.shape
x, y = np.nonzero(image)
ax2=fig.add_subplot(1, 2, 2, aspect='equal')
ax2.scatter(y - Y, -x, s=1, linewidths=0)
ax2.set_xlim(-Y, 0)
ax2.set_ylim(-X, 0)
fig.tight_layout()
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/7aIpl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7aIpl.png" alt="enter image description here"/></a></p>