gpt4 book ai didi

python - 等高线的位置

转载 作者:行者123 更新时间:2023-12-01 04:08:36 25 4
gpt4 key购买 nike

下面是我的代码和情节:

import matplotlib
import matplotlib.mlab as mlab
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

delta = 0.00025
A=0
x = np.arange(0, 0.10, delta)
y = np.arange(0, 0.1, delta)
X, Y = np.meshgrid(x, y)
Z = A*(X**2+Y**2)+2*X*Y

manual_locations = [(0.1,0.1), (0.2,0.2), (0.3,0.3),
(0.015, 0.015), (0.00255, 0.0025), (0.00005,0.00005)]
line_widths = (1, 1, 1, 1, 1, 1)

plt.figure()
CS = plt.contour(X, Y, Z, 6, # add 6 contour lines
linewidths=line_widths, # line widths
colors = line_colours) # line colours

plt.clabel(CS, inline=1, # add labels
fontsize=10, # label font size
manual=manual_locations) # label locations
plt.title('Indifference Map') # title

plt.show()

enter image description here

看来我的manual_locations什么也没做,python自动选择等距的轮廓线。虽然我想研究 0 附近的更多细节。如何才能看到更多曲线/轮廓线收敛到 (0,0)?提前致谢。

最佳答案

更详细地探索部分数据的最简单方法是使用级别。这设置了要检查的 Z 值,在您的问题中,您将其表述为要检查的 (x,y) 位置,但这与 contour 直接指定位置点的工作方式有点倒退。

您还可以通过适当更改绘图的边界来检查 (0,0) 区域。

下面,我使用对数值作为级别,但线性值同样有效,而且更常见,并且更容易解释。对数值很容易强调您最感兴趣的绘图部分。

enter image description here

import matplotlib
import matplotlib.mlab as mlab
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
#%matplotlib inline

delta = 0.00025
A=0
x = np.arange(0, 0.10, delta)
y = np.arange(0, 0.1, delta)
X, Y = np.meshgrid(x, y)
Z = A*(X**2+Y**2)+2*X*Y

manual_locations = [(0.1,0.1), (0.2,0.2), (0.3,0.3),
(0.015, 0.015), (0.00255, 0.0025), (0.00005,0.00005)]
line_widths = (1, 1, 1, 1, 1, 1)

plt.figure()
CS = plt.contour(X, Y, Z, 6, # add 6 contour lines
linewidths=line_widths,
#levels=np.linspace(0, .003, 20))
levels=np.logspace(-5, -2, 20))

plt.clabel(CS, inline=1, # add labels
fontsize=10,
fmt="%.5f")
plt.title('Indifference Map') # title

plt.show()

如果您确实需要特定位置的轮廓,您可以将该位置的 (x,y) 值放入方程中以计算该位置的 z 值,然后使用该值作为其中一个值在 levels 参数中。

关于python - 等高线的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35261452/

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