gpt4 book ai didi

python - python中特定几何图形的二维等值线图

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

我想绘制特定几何图形(多边形)的等高线图。我有这个多边形内的角点和许多点的坐标,以及我想要插入到等值线图的一维参数。我能够绘制参数的分布,但图像显示为正方形(因为我不知道如何指定我的几何形状)。不用说我是一个Python初学者......

我现在使用以下代码;

import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate

r = np.array([[0, 0, 1.0000], [0, 1.0000, 0], [1.0000, 0, 0], [0, 0.7071, 0.7071],
[0, -0.7071, 0.7071],[0.7071, 0, 0.7071], [-0.7071, 0, 0.7071], [0.7071, 0.7071, 0],
[-0.7071, 0.7071, 0], [0.8361, 0.3879, 0.3879], [-0.8361, 0.3879, 0.3879],
[0.8361, -0.3879, 0.3879], [-0.8361, -0.3879, 0.3879], [0.3879, 0.8361, 0.3879],
[-0.3879, 0.8361, 0.3879], [0.3879, -0.8361, 0.3879], [-0.3879, -0.8361, 0.3879],
[0.3879, 0.3879, 0.8361], [-0.3879, 0.3879, 0.8361], [0.3879, -0.3879, 0.8361],
[-0.3879, -0.3879, 0.8361], [-1.0000, 0, 0], [-0.7071, -0.7071, 0], [0, -1.0000, 0],
[0.7071, -0.7071, 0]])

xx = r[:,0]
yy = r[:,1]
zz = r[:,2]

xxi, yyi = np.linspace(xx.min(), xx.max(), 100), np.linspace(yy.min(), yy.max(), 100)
xxi, yyi = np.meshgrid(xxi, yyi)

rbff = scipy.interpolate.Rbf(xx, yy, zz, function='linear')
zzi = rbff(xxi, yyi)
plt.imshow(zzi, vmin=zz.min(), vmax=zz.max(), origin='lower',
extent=[xx.min(), xx.max(), yy.min(), yy.max()])
plt.scatter(xx, yy, c=zz)
plt.colorbar()
plt.show()

最佳答案

这是作弊,但尽管如此:你可以添加类似的东西

zzi = rbff(xxi, yyi)
zzi[zzi<0.1]=nan

并使用该值(目前为 0.1)。

关于python - python中特定几何图形的二维等值线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19914861/

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