Make 2 overlapping lines NOT look thicker

Viewed 136

I would like to plot 2 squares touching eachother, but the common side line appears thicker. How can I avoid that? (I want the linewidth to be 0.1, change it to another value won't solve my problem)

import matplotlib.pyplot as plt

x1 = [0, 1, 1, 0, 0]
x2 = [0, -1, -1, 0, 0]
y = [0, 0, 1, 1, 0]

plt.plot(x1, y, 'k', linewidth = 0.1)
plt.plot(x2, y, 'k', linewidth = 0.1)

Here's a pic: 2 squares overlapping, making the common line thicker

2 Answers

The shared segment is not thicker, it is darker. A line cannot be thinner than 1 pixel. The "thickness" of 0.1 is achieved by making the line look paler.

Having said that, you can avoid the "thickening" of the common edge by not drawing it twice:

plt.plot(x1, y, 'k', linewidth = 0.1)
plt.plot(x2[:-1], y[:-1], 'k', linewidth = 0.1)

The problem is in antialiasing.

See, I changed colors and line widths, so

plt.plot(x1, y, 'r', linewidth = 5)
plt.plot(x2, y, 'g', linewidth = 5)

gives

enter image description here

As you may see, the green line of the second “square” completely overwrites the red one, not increasing the width of the common line.

So the problem is not in matplotlib, but in displaying so narrow lines in the way you wanted, because they are antialiased — you may see it if you zoom in my picture. For instance the upper left corner:

enter image description here

Related