本文整理汇总了Python中matplotlib.pyplot.tricontour方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.tricontour方法的具体用法?Python pyplot.tricontour怎么用?Python pyplot.tricontour使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.tricontour方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: eliso2_mpl
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import tricontour [as 别名]
def eliso2_mpl(ex, ey, ed):
plt.axis('equal')
print(np.shape(ex))
print(np.shape(ey))
print(np.shape(ed))
gx = []
gy = []
gz = []
for elx, ely, scl in zip(ex, ey, ed):
for x in elx:
gx.append(x)
for y in ely:
gy.append(y)
for z in ely:
gz.append(y)
plt.tricontour(gx, gy, gz, 5)
示例2: draw_nodal_values_contour
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import tricontour [as 别名]
def draw_nodal_values_contour(values, coords, edof, levels=12, title=None, dofs_per_node=None, el_type=None, draw_elements=False):
"""Draws element nodal values as filled contours. Element topologies
supported are triangles, 4-node quads and 8-node quads."""
edof_tri = topo_to_tri(edof)
ax = plt.gca()
ax.set_aspect('equal')
x, y = coords.T
v = np.asarray(values)
plt.tricontour(x, y, edof_tri - 1, v.ravel(), levels)
if draw_elements:
if dofs_per_node != None and el_type != None:
draw_mesh(coords, edof, dofs_per_node,
el_type, color=(0.2, 0.2, 0.2))
else:
info("dofs_per_node and el_type must be specified to draw the mesh.")
if title != None:
ax.set(title=title)
示例3: eliso2_mpl
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import tricontour [as 别名]
def eliso2_mpl(ex, ey, ed):
plt.axis('equal')
print(np.shape(ex))
print(np.shape(ey))
print(np.shape(ed))
gx = []
gy = []
gz = []
for elx, ely, scl in zip(ex, ey, ed):
for x in elx:
gx.append(x)
for y in ely:
gy.append(y)
for z in ely:
gz.append(y)
plt.tricontour(gx, gy, gz, 5)
示例4: topo_to_tri
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import tricontour [as 别名]
def topo_to_tri(edof):
"""Converts 2d element topology to triangle topology to be used
with the matplotlib functions tricontour and tripcolor."""
if edof.shape[1] == 3:
return edof
elif edof.shape[1] == 4:
new_edof = np.zeros((edof.shape[0]*2, 3), int)
new_edof[0::2, 0] = edof[:, 0]
new_edof[0::2, 1] = edof[:, 1]
new_edof[0::2, 2] = edof[:, 2]
new_edof[1::2, 0] = edof[:, 2]
new_edof[1::2, 1] = edof[:, 3]
new_edof[1::2, 2] = edof[:, 0]
return new_edof
elif edof.shape[1] == 8:
new_edof = np.zeros((edof.shape[0]*6, 3), int)
new_edof[0::6, 0] = edof[:, 0]
new_edof[0::6, 1] = edof[:, 4]
new_edof[0::6, 2] = edof[:, 7]
new_edof[1::6, 0] = edof[:, 4]
new_edof[1::6, 1] = edof[:, 1]
new_edof[1::6, 2] = edof[:, 5]
new_edof[2::6, 0] = edof[:, 5]
new_edof[2::6, 1] = edof[:, 2]
new_edof[2::6, 2] = edof[:, 6]
new_edof[3::6, 0] = edof[:, 6]
new_edof[3::6, 1] = edof[:, 3]
new_edof[3::6, 2] = edof[:, 7]
new_edof[4::6, 0] = edof[:, 4]
new_edof[4::6, 1] = edof[:, 6]
new_edof[4::6, 2] = edof[:, 7]
new_edof[5::6, 0] = edof[:, 4]
new_edof[5::6, 1] = edof[:, 5]
new_edof[5::6, 2] = edof[:, 6]
return new_edof
else:
error("Element topology not supported.")
示例5: test_tri_smooth_contouring
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import tricontour [as 别名]
def test_tri_smooth_contouring():
# Image comparison based on example tricontour_smooth_user.
n_angles = 20
n_radii = 10
min_radius = 0.15
def z(x, y):
r1 = np.sqrt((0.5-x)**2 + (0.5-y)**2)
theta1 = np.arctan2(0.5-x, 0.5-y)
r2 = np.sqrt((-x-0.2)**2 + (-y-0.2)**2)
theta2 = np.arctan2(-x-0.2, -y-0.2)
z = -(2*(np.exp((r1/10)**2)-1)*30. * np.cos(7.*theta1) +
(np.exp((r2/10)**2)-1)*30. * np.cos(11.*theta2) +
0.7*(x**2 + y**2))
return (np.max(z)-z)/(np.max(z)-np.min(z))
# First create the x and y coordinates of the points.
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0 + n_angles, 2*np.pi + n_angles,
n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi/n_angles
x0 = (radii*np.cos(angles)).flatten()
y0 = (radii*np.sin(angles)).flatten()
triang0 = mtri.Triangulation(x0, y0) # Delaunay triangulation
z0 = z(x0, y0)
xmid = x0[triang0.triangles].mean(axis=1)
ymid = y0[triang0.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang0.set_mask(mask)
# Then the plot
refiner = mtri.UniformTriRefiner(triang0)
tri_refi, z_test_refi = refiner.refine_field(z0, subdiv=4)
levels = np.arange(0., 1., 0.025)
plt.triplot(triang0, lw=0.5, color='0.5')
plt.tricontour(tri_refi, z_test_refi, levels=levels, colors="black")
示例6: test_tri_smooth_contouring
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import tricontour [as 别名]
def test_tri_smooth_contouring():
# Image comparison based on example tricontour_smooth_user.
n_angles = 20
n_radii = 10
min_radius = 0.15
def z(x, y):
r1 = np.sqrt((0.5-x)**2 + (0.5-y)**2)
theta1 = np.arctan2(0.5-x, 0.5-y)
r2 = np.sqrt((-x-0.2)**2 + (-y-0.2)**2)
theta2 = np.arctan2(-x-0.2, -y-0.2)
z = -(2*(np.exp((r1/10)**2)-1)*30. * np.cos(7.*theta1) +
(np.exp((r2/10)**2)-1)*30. * np.cos(11.*theta2) +
0.7*(x**2 + y**2))
return (np.max(z)-z)/(np.max(z)-np.min(z))
# First create the x and y coordinates of the points.
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0 + n_angles, 2*np.pi + n_angles,
n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi/n_angles
x0 = (radii*np.cos(angles)).flatten()
y0 = (radii*np.sin(angles)).flatten()
triang0 = mtri.Triangulation(x0, y0) # Delaunay triangulation
z0 = z(x0, y0)
triang0.set_mask(np.hypot(x0[triang0.triangles].mean(axis=1),
y0[triang0.triangles].mean(axis=1))
< min_radius)
# Then the plot
refiner = mtri.UniformTriRefiner(triang0)
tri_refi, z_test_refi = refiner.refine_field(z0, subdiv=4)
levels = np.arange(0., 1., 0.025)
plt.triplot(triang0, lw=0.5, color='0.5')
plt.tricontour(tri_refi, z_test_refi, levels=levels, colors="black")
示例7: test_tri_smooth_gradient
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import tricontour [as 别名]
def test_tri_smooth_gradient():
# Image comparison based on example trigradient_demo.
def dipole_potential(x, y):
""" An electric dipole potential V """
r_sq = x**2 + y**2
theta = np.arctan2(y, x)
z = np.cos(theta)/r_sq
return (np.max(z)-z) / (np.max(z)-np.min(z))
# Creating a Triangulation
n_angles = 30
n_radii = 10
min_radius = 0.2
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi/n_angles
x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
V = dipole_potential(x, y)
triang = mtri.Triangulation(x, y)
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
# Refine data - interpolates the electrical potential V
refiner = mtri.UniformTriRefiner(triang)
tri_refi, z_test_refi = refiner.refine_field(V, subdiv=3)
# Computes the electrical field (Ex, Ey) as gradient of -V
tci = mtri.CubicTriInterpolator(triang, -V)
(Ex, Ey) = tci.gradient(triang.x, triang.y)
E_norm = np.sqrt(Ex**2 + Ey**2)
# Plot the triangulation, the potential iso-contours and the vector field
plt.figure()
plt.gca().set_aspect('equal')
plt.triplot(triang, color='0.8')
levels = np.arange(0., 1., 0.01)
cmap = cm.get_cmap(name='hot', lut=None)
plt.tricontour(tri_refi, z_test_refi, levels=levels, cmap=cmap,
linewidths=[2.0, 1.0, 1.0, 1.0])
# Plots direction of the electrical vector field
plt.quiver(triang.x, triang.y, Ex/E_norm, Ey/E_norm,
units='xy', scale=10., zorder=3, color='blue',
width=0.007, headwidth=3., headlength=4.)
示例8: test_tri_smooth_gradient
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import tricontour [as 别名]
def test_tri_smooth_gradient():
# Image comparison based on example trigradient_demo.
def dipole_potential(x, y):
""" An electric dipole potential V """
r_sq = x**2 + y**2
theta = np.arctan2(y, x)
z = np.cos(theta)/r_sq
return (np.max(z)-z) / (np.max(z)-np.min(z))
# Creating a Triangulation
n_angles = 30
n_radii = 10
min_radius = 0.2
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi/n_angles
x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
V = dipole_potential(x, y)
triang = mtri.Triangulation(x, y)
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
y[triang.triangles].mean(axis=1))
< min_radius)
# Refine data - interpolates the electrical potential V
refiner = mtri.UniformTriRefiner(triang)
tri_refi, z_test_refi = refiner.refine_field(V, subdiv=3)
# Computes the electrical field (Ex, Ey) as gradient of -V
tci = mtri.CubicTriInterpolator(triang, -V)
(Ex, Ey) = tci.gradient(triang.x, triang.y)
E_norm = np.sqrt(Ex**2 + Ey**2)
# Plot the triangulation, the potential iso-contours and the vector field
plt.figure()
plt.gca().set_aspect('equal')
plt.triplot(triang, color='0.8')
levels = np.arange(0., 1., 0.01)
cmap = cm.get_cmap(name='hot', lut=None)
plt.tricontour(tri_refi, z_test_refi, levels=levels, cmap=cmap,
linewidths=[2.0, 1.0, 1.0, 1.0])
# Plots direction of the electrical vector field
plt.quiver(triang.x, triang.y, Ex/E_norm, Ey/E_norm,
units='xy', scale=10., zorder=3, color='blue',
width=0.007, headwidth=3., headlength=4.)
# We are leaving ax.use_sticky_margins as True, so the
# view limits are the contour data limits.