在 matplotlib 中使用 tripcolor 透明度时是否可以防止出现线条

问题描述 投票:0回答:0

我正在使用 tripcolor 在 matplotlib 中绘制阴影形状。我希望形状与透明度重叠并且阴影平滑。

在示例中,具有透明度的形状在三角剖分三角形接触的位置有线。我不想要这些线条,我想要像图中橙色方块那样的平滑过渡。如果这在 matplotlib 中是不可能的,那么在任何其他绘图模块中是否可能?示例代码使用 matplotlib 3.7。为了清楚起见,我正在绘制正方形,但形状可以是任何形状。

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

x = (np.linspace(0, 0.4, 10) * np.ones((10, 10))).flatten()
y = (np.linspace(0, 0.4, 10) * np.ones((10, 10))).T.flatten()
z = (x+y).flatten()

t1 = tri.Triangulation(x, y)
t2 = tri.Triangulation(x+0.25, y+0.25)
t3 = tri.Triangulation(x+0.50, y+0.50)

fig, ax = plt.subplots()
ax.tripcolor(t1, z, shading='gouraud', cmap='Oranges', alpha=None)
ax.tripcolor(t2, z, shading='gouraud', cmap='Greys',   alpha=0.5)
ax.tripcolor(t3, z, shading='flat', cmap='Blues',   alpha=0.5)

enter image description here

matplotlib alpha-transparency
© www.soinside.com 2019 - 2024. All rights reserved.