gpt4 book ai didi

python - matplotlib 中轴 ('equal' ) 和轴 ('scaled' ) 的区别

转载 作者:太空宇宙 更新时间:2023-11-03 14:52:18 25 4
gpt4 key购买 nike

在引用文献中,它们被描述为:

axis('equal') changes limits of x or y axis so that equal increments of x and y have the same length; a circle is circular.:

axis('scaled') achieves the same result by changing the dimensions of the plot box instead of the axis data limits.:

但我不理解“通过改变绘图框的尺寸”部分。于是直接对比

import numpy as np
import matplotlib.pyplot as plt

plt.close('all')

x = np.array(np.linspace(-np.pi, np.pi))
y = np.sin(x)

ax1 = plt.subplot(2, 1, 1)
ax1 = plt.plot(x, y)
plt.axis('scaled')

ax1 = plt.subplot(2, 1, 2)
plt.plot(x, y)
plt.axis('equal')

enter image description here

只有一点点不同,就是用 plt.axis('scaled') 绘制时宽度变短了。

我怎样才能更好地了解差异?

最佳答案

我认为如果使用不同的数据,差异会更加明显。

import numpy as np
import matplotlib.pyplot as plt

x = np.array(np.linspace(-np.pi, np.pi))
y = np.sin(x)*np.pi
ax1 = plt.subplot(2, 1, 1)
ax1 = plt.plot(x, y)
plt.axis('scaled')
ax1 = plt.subplot(2, 1, 2)
plt.plot(x, y)
plt.axis('equal')
plt.show()

enter image description here

所以不同之处在于,如果绘图周围的轴根据方面进行更改,或者如果它们与通常的子图中保持相同并按比例缩放,则绘图数据的方面是相等的。

关于python - matplotlib 中轴 ('equal' ) 和轴 ('scaled' ) 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45057647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com