I’m trying to plot two thick lines that are separated only by a constant.
import matplotlib.pyplot as plt
import numpy as np
shift = .1
x = np.linspace(0,10,100)
y1 = np.sin(x)
y2 = y1 + shift
lw = 10
alpha = .8
plt.plot(x, y1, linewidth=lw, alpha=alpha)
plt.plot(x, y2, linewidth=lw, alpha=alpha)
Visually, the result is not desirable. The thickness of lines seems to be handled by drawing perpendiculars along the line, and the effect is that when the derivative of the line is small, the lines appear further apart then when the derivative is large. When plotting a family of sine waves separated only by constants, this definitely gives the wrong impression. Of course, I can try to force the lines to be right on top of each other:
ymid = y1 + shift/2.0
yhigh = ymid + shift
ylow = ymid - shift
But this has the undesirable effect that the thickness of the lines appears non-uniform.
What I am after is a way to draw lines separated by constant values such that the thickness of the lines appears constant AND such that the thickness of the distance between the lines also appears constant. It seems that this could be done if the thickness of the line varied (in just the right way) as a function of the derivative of the line. I could also achieve this if I doubled the line thickness and was able to color the top and bottom halves of the thick lines different colors.
Is there a nice way to do this?