Hi, I’m using the LineCollection object to make the line multicolored. But as you can see, for some reason it’s not fully opaque (both parts of the line are visible at a point of intersection). I set alpha to 1.0, but it doesn’t help. The line consists of about 100,000 points.
Thanks in advance for any help or suggestions.
Here’s the code:
x = np.array(x)
y = np.array(y)
# Create a list of line segments
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
# Create a LineCollection object with multicolored line segments
# (C is a list of colors that looks like [(0.1, 0.2, 0.3), (0.2, 0.3, 0.4)...]
lc = LineCollection(segments, colors=C, linewidths=25, alpha=1.0)
# Create a figure and axis object
fig, ax = plt.subplots(figsize=(12, 12))
# Set the background color of the plot
fig.set_facecolor('white')
# Add the LineCollection to the axis
ax.add_collection(lc)
# Set the axis limits
x_range = x.max() - x.min()
y_range = y.max() - y.min()
R = 0.05
ax.set_xlim(x.min() - x_range * R, x.max() + x_range * R)
ax.set_ylim(y.min() - y_range * R, y.max() + y_range * R)
ax.set_aspect('equal', 'datalim')
ax = plt.gca()
plt.axis('off')
# Show the plot
plt.show()