[英]Plot deformed 2D mesh with Python
I want to plot a deformed rectangular mesh, which means that the coordinates of the nodes depend on the indices of the node. 我想绘制一个变形的矩形网格,这意味着节点的坐标取决于节点的索引。 The purpose is to visualize the deformation of unit square by a function.
目的是通过函数可视化单位平方的变形。
How can I do that in python? 我怎么能在python中做到这一点?
This is the type of thing that pcolormesh
(or pcolor
) is meant for. 这是
pcolormesh
(或pcolor
)的意思。 (Also have a look at triplot
, etc for triangular meshes.) (另请查看三角网格的
triplot
等。)
import matplotlib.pyplot as plt
y, x = np.mgrid[:10, :10]
z = np.random.random(x.shape)
xdef, ydef = x**2, y**2 + x
fig, axes = plt.subplots(ncols=2)
axes[0].pcolormesh(x, y, z, cmap='gist_earth')
axes[1].pcolormesh(xdef, ydef, z, cmap='gist_earth')
axes[0].set(title='Original', xticks=[], yticks=[])
axes[1].set(title='Deformed', xticks=[], yticks=[])
plt.show()
On a side note, pcolormesh
defaults to using no antialiasing for performance reasons. 另外,由于性能原因,
pcolormesh
默认不使用抗锯齿。 If you add antiailiased=True
to the pcolormesh
call, you'll get a nicer-looking result: 如果你在
pcolormesh
调用中添加antiailiased=True
,你会得到一个更好看的结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.