I want to have a single line that has two colors in parallel, e.g. for green and red:
I have achieved this as follows:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,100)
y = np.exp(x)
plt.plot(x,y,color='r')
plt.plot(x,y 0.01,color='g')
plt.show()
The problem is that when I zoom in the lines start to separate. Is there anyway to plot a single line that has two parallel colors?
CodePudding user response:
Use linewidth
argument:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,100)
y = np.exp(x)
plt.plot(x,y,color='r', linewidth=4)
plt.plot(x,y 0.01,color='g', linewidth=4)
plt.show()
CodePudding user response:
Are you wanting only line
or is OK another shape of lines like below:
Format Strings A format string consists of a part for color, marker and line:: fmt = '[marker][line][color]'
'-'
solid line style'--'
dashed line style'-.'
dash-dot line style':'
dotted line style
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,100)
y = np.exp(x)
fig, axe = plt.subplots(figsize=(15,10))
axe.plot(x,y,'-.r', linewidth=3)
axe.plot(x,y 0.015,':g', linewidth=3)
plt.show()
Output: