擅长:python、mysql、java
<p>问题在于不相等的轴,这使它看起来像他们不是在一个直角。使用<code>plt.axis('equal')</code>使x轴和y轴上的轴跨度相等,并使正方形具有相同的高度和宽度。<code>plt.axis('scaled')</code>也是这样。正如@CedricZoppolo所指出的,应该在<code>plt.show()</code>之前设置相等的纵横比。根据文档,将纵横比设置为“相等”意味着</p>
<blockquote>
<p>same scaling from data to plot units for x and y</p>
</blockquote>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8,8))
# Your code here
plt.axis('equal')
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/zF2h5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zF2h5.png" alt="enter image description here"/></a></p>
<p>选择一个正方形的图形是没有必要的,因为它也适用于矩形图形作为</p>
<pre><code>fig = plt.figure(figsize=(8,6))
# Your code here
plt.axis('equal')
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/cKPDm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cKPDm.png" alt="enter image description here"/></a></p>