【发布时间】:2014-09-28 04:22:07
【问题描述】:
我正在尝试更改三色图形的不透明度。设置 alpha 参数会改变不透明度,但也会显示网格。我认为这是因为 alpha 参数也没有改变边缘的不透明度。我试图设置 edgecolor='none' 但这并不能解决我的问题。有没有办法改变不透明度而不显示网格?
"""
Pseudocolor plots of unstructured triangular grids.
"""
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np
import math
# Creating a Triangulation without specifying the triangles results in the
# Delaunay triangulation of the points.
# First create the x and y coordinates of the points.
n_angles = 36
n_radii = 8
min_radius = 0.25
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
angles[:,1::2] += math.pi/n_angles
x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
# Create the Triangulation; no triangles so Delaunay triangulation created.
triang = tri.Triangulation(x, y)
# Mask off unwanted triangles.
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)
# Illustrate Gouraud shading.
plt.figure()
plt.gca().set_aspect('equal')
plt.tripcolor(triang, z, shading='gouraud', cmap=plt.cm.rainbow, alpha=0.5, edgecolor='none')
plt.colorbar()
plt.title('tripcolor of Delaunay triangulation, gouraud shading')
plt.show()
非常感谢您的宝贵时间,
多林
【问题讨论】:
-
似乎与
gauraud阴影有关。如果您从.tripcolor捕获路径并再次将它们添加为路径集合,它看起来很好(但没有适当的阴影)。这表明三角形很好,没有重叠或任何东西,这是我最初怀疑的。 -
@RutgerKassies 非常感谢您的快速重播。我是 matplotlib 的新手,我不完全理解你的答案。我做了这样的事情: plt.figure() ax = plt.gca() ax.set_aspect('equal') trip = ax.tripcolor(triang, z, shading='gouraud', cmap=plt.cm.rainbow , alpha=0.5, edgecolor='none') path = trip.get_paths() collection = mcoll.PathCollection(path, edgecolors=z) ax.add_collection(collection) 但情节真的很奇怪。您可以复制并粘贴您评论中描述的代码行吗?非常感谢。
标签: matplotlib opacity alpha mesh