当我给更多数据点时,matplotlib tricontourf问题

YONG BAGJNS

当我尝试绘制压力时出现问题。

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
import matplotlib.cm as cm

def plot(x_plot, y_plot, a_plot):
    x = np.array(x_plot)
    y = np.array(y_plot)
    a = np.array(a_plot)

    triang = mtri.Triangulation(x, y)
    refiner = mtri.UniformTriRefiner(triang)
    tri_refi, z_test_refi = refiner.refine_field(a, subdiv=4)

    plt.figure(figsize=(18, 9))
    plt.gca().set_aspect('equal')
    #     levels = np.arange(23.4, 23.7, 0.025)
    levels = np.linspace(a.min(), a.max(), num=1000)
    cmap = cm.get_cmap(name='jet')
    plt.tricontourf(tri_refi, z_test_refi, levels=levels, cmap=cmap)
    plt.scatter(x, y, c=a, cmap=cmap)
    plt.colorbar()

    plt.title('stress plot')
    plt.show()

首先,我仅使用8个点进行绘图:

x = [2.3384750000000003, 3.671702, 0.3356813, 3.325298666666667, 2.660479, 1.3271675666666667, 1.6680919666666665, 0.6659845666666667]
y = [0.614176, 0.5590579999999999, 0.663329, 0.24002166666666666, 0.26821433333333333, 0.31229233333333334, 0.6367503333333334, 0.3250663333333333]
a = [2.572, 0.8214, 5.689, -0.8214, -2.572, -4.292, 4.292, -5.689]
plot(x, y, a)

版本A

然后我尝试给出矩形边界的信息:

x = [2.3384750000000003, 1.983549, 3.018193, 2.013683, 3.671702, 3.978008, 4.018905, 0.3356813, 0.0, 0.0, 1.0070439, 3.325298666666667, 2.979695, 2.660479, 1.3271675666666667, 0.9909098, 1.6680919666666665, 0.6659845666666667]
y = [0.614176, -0.038322, 0.922264, 0.958586, 0.5590579999999999, -0.1229, 0.87781, 0.663329, 1.0, 0.0, 0.989987, 0.24002166666666666, -0.079299, 0.26821433333333333, 0.31229233333333334, -0.014787999999999999, 0.6367503333333334, 0.3250663333333333]
a = [2.572, 2.572, 2.572, 2.572, 0.8214, 0.8214, 0.8214, 5.689, 5.689, 5.689, 5.689, -0.8214, -0.8214, -2.572, -4.292, -4.292, 4.292, -5.689]
plot(x, y, a)

版本b

我不知道如何解决它,为什么会这样。我想要的数字是:

影印版

我已经在第二张图中绘制了每个点的散点图,并且正确,但是为什么颜色不是轮廓。

非常感谢你。

认真的重要性

UniformTriRefiner在附加点的情况下,由返回的字段不能很好地插值。相反,它引入了新的最小值和最大值,其最大值比原始点大20倍。

下图显示了正在发生的事情。

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
import matplotlib.cm as cm

def plot(x_plot, y_plot, a_plot, ax=None):
    if ax == None: ax = plt.gca()
    x = np.array(x_plot)
    y = np.array(y_plot)
    a = np.array(a_plot)

    triang = mtri.Triangulation(x, y)
    refiner = mtri.UniformTriRefiner(triang)
    tri_refi, z_test_refi = refiner.refine_field(a, subdiv=2)

    levels = np.linspace(z_test_refi.min(), z_test_refi.max(), num=100)
    cmap = cm.get_cmap(name='jet')

    tric = ax.tricontourf(tri_refi, z_test_refi, levels=levels, cmap=cmap)
    ax.scatter(x, y, c=a, cmap=cmap, vmin= z_test_refi.min(),vmax= z_test_refi.max())
    fig.colorbar(tric, ax=ax)

    ax.set_title('stress plot')

fig, (ax, ax2) = plt.subplots(nrows=2, sharey=True,sharex=True, subplot_kw={"aspect":"equal"} )
    
x = [2.3384750000000003, 3.671702, 0.3356813, 3.325298666666667, 2.660479, 1.3271675666666667, 1.6680919666666665, 0.6659845666666667]
y = [0.614176, 0.5590579999999999, 0.663329, 0.24002166666666666, 0.26821433333333333, 0.31229233333333334, 0.6367503333333334, 0.3250663333333333]
a = [2.572, 0.8214, 5.689, -0.8214, -2.572, -4.292, 4.292, -5.689]
plot(x, y, a, ax)


x = [2.3384750000000003, 1.983549, 3.018193, 2.013683, 3.671702, 3.978008, 4.018905, 0.3356813, 0.0, 0.0, 1.0070439, 3.325298666666667, 2.979695, 2.660479, 1.3271675666666667, 0.9909098, 1.6680919666666665, 0.6659845666666667]
y = [0.614176, -0.038322, 0.922264, 0.958586, 0.5590579999999999, -0.1229, 0.87781, 0.663329, 1.0, 0.0, 0.989987, 0.24002166666666666, -0.079299, 0.26821433333333333, 0.31229233333333334, -0.014787999999999999, 0.6367503333333334, 0.3250663333333333]
a = [2.572, 2.572, 2.572, 2.572, 0.8214, 0.8214, 0.8214, 5.689, 5.689, 5.689, 5.689, -0.8214, -0.8214, -2.572, -4.292, -4.292, 4.292, -5.689]
plot(x, y, a, ax2)

plt.show()

在此处输入图片说明

As can be seen, the values of the "interpolated" field overshoot the original values by a large amount.
The reason is that by default, UniformTriRefiner.refine_field uses a cubic interpolation (a CubicTriInterpolator). The documentation states

The interpolation is based on a Clough-Tocher subdivision scheme of the triangulation mesh (to make it clearer, each triangle of the grid will be divided in 3 child-triangles, and on each child triangle the interpolated function is a cubic polynomial of the 2 coordinates). This technique originates from FEM (Finite Element Method) analysis; the element used is a reduced Hsieh-Clough-Tocher (HCT) element. Its shape functions are described in 1. The assembled function is guaranteed to be C1-smooth, i.e. it is continuous and its first derivatives are also continuous (this is easy to show inside the triangles but is also true when crossing the edges).

在默认情况下(kind ='min_E'),插值HCT元素形状函数生成的函数空间上的曲率能量最小化-在每个节点处具有强制值但具有任意导数。

尽管这确实是非常技术性的,但我还是强调了一些重要的方面,即插值是平滑且连续的,并具有定义的导数。为了保证这种行为,当数据非常稀疏但幅度波动较大时,过冲是不可避免的。

在此,该数据根本不适合三次插值。要么尝试获取更密集的数据,要么使用线性插值。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

设置Matplotlib Tricontourf的蒙版

屏蔽 tricontourf 中的大量缺失数据

尝试获取更多数据(如“字段”)时使用 JSON 的问题

当我有更多数据时,选择数据非常慢

每当我带来更多数据时重复一些项目?

放大时如何在D3.js上绘制更多数据点?

我有一个问题,当我放多个 url 时,数据会被覆盖

我的mybatis有一些问题,当我查询presto数据时

当我尝试在 MySQL 中将数据插入数据库时遇到问题

绘制三角形轮廓/曲面 matplotlib python:tricontourf/meshgrid

当我将数据从控制器传递给作业时,Laravel 会出现排队问题

当我尝试在数据矩阵上添加一层时出现问题(python)

当我尝试使用可编辑选项更新数据时,configureListFields问题

MQTT问题:当我发送连接数据包时,代理关闭连接

我想让精灵面对鼠标,我想我已经解决了大多数问题,但还有更多问题

matplotlib - 尝试添加更多列时的形状不匹配问题

从 api 抓取的数据中消除无效数据点时遇到问题

我在获取图像路径时遇到问题,当我在活动结果数据中获取图像时,结果数据不为空但无法获取其路径

我在将数据导入到asp.net页面时遇到问题,当我打开页面时,我发现所有文件都为空

当我们拥有数值和分类数据时,哪种算法可用于聚类问题?

触发问题,它可以正常编译,但是当我尝试更新数据时,它不会触发文本消息

当我按下返回时导航片段的问题

当我使用hsqldb时,GUI(JavaFx)出现问题

当我尝试快速绘制渐变时出现问题

当我想导入CSV文件时出现问题

当我更新 gradle build 时出现问题

当我尝试运行npm时出现问题

当我从 php 调用 python 脚本时的权限/用户问题

当我在 c 中调用函数时出现问题