gpt4 book ai didi

python - 从 matplotlib 中的轮廓获取坐标?

转载 作者:太空狗 更新时间:2023-10-29 21:26:47 25 4
gpt4 key购买 nike

背景

来自 the documentation example here ,可以使用代码片段轻松生成以下等高线图。

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

matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)

# Create a simple contour plot with labels using default colors. The
# inline argument to clabel will control whether the labels are draw
# over the line segments of the contour, removing the lines beneath
# the label
plt.figure()
CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')

enter image description here

我的目标

我已经获得了等高线图,同时获得了 matplotlib.contour.QuadContourSet 实例 CS。在示例片段中,CS 仅用于 clabel()。然而,对于我的情况,我需要获取等高线方程或坐标集以供进一步计算。

如何从实例 CS 中提取轮廓线的坐标?或者我怎样才能通过其他方式实现它?

我敢打赌一定有办法做到这一点。否则,轮廓的东西就只是一个“观想的花瓶”。

最佳答案

您可以从 CS.allsegs 列表中获取轮廓的坐标。

尝试:

dat0= CS.allsegs[0][0]
plt.plot(dat0[:,0],dat0[:,1])

绘制第一个 (-1) 等高线水平。

关于python - 从 matplotlib 中的轮廓获取坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19418901/

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