- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个二维数据和二维四边形网格,描述了一个分割为小块的域。数据在每个网格节点处定义。数据的不连续性存在于补丁边界,即数据在同一位置被多次定义。
我如何使用 Python 在节点之间通过线性插值绘制此数据并正确表示沿每个面片的不连续值?
下面是三个示例元素或补丁,每个都有六个节点值。
节点位置和值数据可能存储在 [Kx3x2]
数组中,其中 K 是元素的数量。例如,
x = np.array( [
[ [0.0, 1.0], [0.0, 1.0], [0.0, 1.0] ], #element 0
[ [1.0, 2.0], [1.0, 2.0], [1.0, 2.0] ], #element 1
[ [2.0, 3.0], [2.0, 3.0], [2.0, 3.0] ], #element 2
] )
y = np.array( [
[ [0.0, 0.0], [0.5, 0.5], [1.0, 1.0] ], #element 0
[ [0.0, 1.0], [0.5, 1.5], [1.0, 2.0] ], #element 1
[ [1.0, 1.0], [1.5, 1.5], [2.0, 2.0] ], #element 2
] )
z = np.array( [
[ [0.0, 0.5], [0.0, 0.8], [0.0, 1.0] ], #element 0
[ [0.3, 1.0], [0.6, 1.2], [0.8, 1.3] ], #element 1
[ [1.2, 1.5], [1.3, 1.4], [1.5, 1.7] ], #element 2
] )
我考虑过 pyplot.imshow()
。这不能同时考虑整个域并且仍然表示多值不连续节点。为每个补丁单独调用 imshow()
可能会起作用。但是,我如何在同一轴上绘制每个补丁图像? imshow()
对于非矩形补丁也是有问题的,这是我的一般情况。
我考虑过 pyplot.pcolormesh()
,但它似乎只适用于以单元格为中心的数据。
最佳答案
一个选项通过对所有元素进行三角测量然后使用 matplotlib tripcolor()
绘图来工作我现在发现的功能。两个有用的演示是 here和 here .
我的全局域的自动三角剖分可能会有问题,但单个四边形的 Delaunay 三角剖分效果很好:
我通过附加每个元素的三角剖分来创建全局三角剖分。这意味着共享节点实际上在位置数组和值数组中是重复的。这允许元素面处的不连续数据。
使用 tripcolor()
函数可以根据需要绘制线性插值和不连续点,提供节点位置和每个节点的值。
我有点担心等高线绘图可能如何工作,因为元素面不再逻辑连接。 tricontour()
仍然按预期工作。 (此处显示有三角测量覆盖)
转载代码如下:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
x = np.array( [
[ [0.0, 1.0], [0.0, 1.0], [0.0, 1.0] ], #element 0
[ [1.0, 2.0], [1.0, 2.0], [1.0, 2.0] ], #element 1
[ [2.0, 3.0], [2.0, 3.0], [2.0, 3.0] ], #element 2
] )
y = np.array( [
[ [0.0, 0.0], [0.5, 0.5], [1.0, 1.0] ], #element 0
[ [0.0, 1.0], [0.5, 1.5], [1.0, 2.0] ], #element 1
[ [1.0, 1.0], [1.5, 1.5], [2.0, 2.0] ], #element 2
] )
z = np.array( [
[ [0.0, 0.5], [0.0, 0.8], [0.0, 1.0] ], #element 0
[ [0.3, 1.0], [0.6, 1.2], [0.8, 1.3] ], #element 1
[ [1.2, 1.5], [1.3, 1.4], [1.5, 1.7] ], #element 2
] )
global_num_pts = z.size
global_x = np.zeros( global_num_pts )
global_y = np.zeros( global_num_pts )
global_z = np.zeros( global_num_pts )
global_triang_list = list()
offset = 0;
num_triangles = 0;
#process triangulation element-by-element
for k in range(z.shape[0]):
points_x = x[k,...].flatten()
points_y = y[k,...].flatten()
z_element = z[k,...].flatten()
num_points_this_element = points_x.size
#auto-generate Delauny triangulation for the element, which should be flawless due to quadrilateral element shape
triang = tri.Triangulation(points_x, points_y)
global_triang_list.append( triang.triangles + offset ) #offseting triangle indices by start index of this element
#store results for this element in global triangulation arrays
global_x[offset:(offset+num_points_this_element)] = points_x
global_y[offset:(offset+num_points_this_element)] = points_y
global_z[offset:(offset+num_points_this_element)] = z_element
num_triangles += triang.triangles.shape[0]
offset += num_points_this_element
#go back and turn all of the triangle indices into one global triangle array
offset = 0
global_triang = np.zeros( (num_triangles, 3) )
for t in global_triang_list:
global_triang[ offset:(offset+t.shape[0] )] = t
offset += t.shape[0]
plt.figure()
plt.gca().set_aspect('equal')
plt.tripcolor(global_x, global_y, global_triang, global_z, shading='gouraud' )
#plt.tricontour(global_x, global_y, global_triang, global_z )
#plt.triplot(global_x, global_y, global_triang, 'go-') #plot just the triangle mesh
plt.xlim((-0.25, 3.25))
plt.ylim((-0.25, 2.25))
plt.show()
关于python:如何绘制二维不连续的以节点为中心的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15774199/
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: How to align a to the middle of the page 这是一个简单的问题,应该有一个简
我想知道如何在屏幕中央的ListView中生成2个itens。 class _CategoriesState extends State { List categories = ["Anterio
我需要修复 UICollectionView 的一个小问题,当在 6s 设备尺寸上时,我得到如下布局: 但是,我想知道将它们居中以使其成为两条线的最佳方法是什么,或者我应该将它们缩小一点以便可以放置其
我尝试在 UIImageView 中居中 CAShapeLayer 但没有成功,我找到了解决方案,将其(CAShapeLayer)添加到 UIVIew,然后将 UIVIew 添加到 ImageView
一直在从线性布局和相对布局切换,因为我想实现图像的居中。 显示图片:
* { margin:0; padding:0; } /** General Style Info **/ body { background: #003d4c; co
我目前正在尝试修改我在 Wordpress 上的 Royal Slider 插件 (http://dimsemenov.com/plugins/royal-slider/) 我的目标是将所有标题的文本
我已经坚持了一段时间,因此简化了我的要求。当您单击标记时,信息窗口将打开,当用户缩放时,我希望该标记位于 map 的中心。这不起作用,但我认为它很接近: function bindInfoWindow
/* Linked Styles */ body { padding: 0 !important;
这个问题在这里已经有了答案: How do I center floated elements? (12 个答案) 关闭 7 年前。
这个问题在这里已经有了答案: Is there an equivalent to background-size: cover and contain for image elements? (1
我试图让我的页眉停留在页面的中间,不管我在什么窗口大小。 我试过使用 Bootstrap。 StackOverflow 还有这个 CSS。 .section-t
我有一个 1600 像素宽的页面。主要区域虽然只有 900 像素宽。我有一个导航应该固定在页面的中心(它是)。我的问题是当我打开页面时,页面固定在左侧而不是在打开时居中。当用户访问该网站时,我需要做什
我正在尝试找到 View 的中心。对于非旋转 View ,该值是正确的,但对于旋转 View ,它不正确,因为中心 (0,0) 正在旋转。在缩放的情况下,即使缩放后宽度和高度也保持不变 我正在使用以下
预期效果是将 Kartennummer 和 Passwort 集中。 这怎么可能? 我为此使用了一个自定义类: import 'package:flutter/material.dart'; impo
我管理着许多 Maven 项目。他们中的大多数部署到我们的内部 maven 存储库。现在我想开始向 Maven Central 发布一个项目。到目前为止,我有一个父 POM,它指定了我们内部存储库的
我试图锚定两个进展,但我看不到获得预期结果的方法。 我希望左边的进度条固定在左边,右边的条固定在中心固定(如下图所示) (下图显示调整大小的表格) 我尝试将控件放在具有各种 anchor 的停靠面板上
我正在玩 Angular 模态 ui 对话框。我想知道有什么方法可以让它居中?我发现了一个类似的问题: Twitter Bootstrap - Center Modal Dialog 但无法使其工作,
是否可以将值标签放置在条形上,使它们位于条形的中心? 如果我设置条形 align: "center",则条形上的标签将关闭且不居中。 $(function() { var d
http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-s
我是一名优秀的程序员,十分优秀!