An issue with shaded transparency using triangulation and tripcolor in matplotlib

86 Views Asked by At

I'm using tripcolor to plot shaded shapes in matplotlib. I want the shapes to overlap with transparency and the shading to be smooth.

In the example, the shapes with transparency have lines where the triangulation triangles touch. I do not want these lines, I want a smooth transition like the orange square in the figure. If this is not possible in matplotlib, is it possible in any of the other plotting modules? The example code uses matplotlib 3.7. I'm plotting squares for clarity, but the shapes can be any shape.

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)

click here for figure

0

There are 0 best solutions below