I am trying to create a line figure with four different line styles. I have mean values for y axis and error for each y value. Because I want it to be all same color (black), I want to differentiate them by different line styles but with my code below, I get fine solid line for all four so the line styles do not look so distinct. What am I doing wrong?
import matplotlib.pyplot as plt
import numpy as np
xl = [1, 2, 3, 4, 5, 6]
a_mean = [17, 15, 20, 22, 18, 16]
a_se = [1, 2, 1, 3, 1.5, 2]
b_mean = [5, 6, 2, 5, 1, 9]
b_se = [1, 2, 0.3, 1, 2, 1]
c_mean = [2, 4, 6, 8, 10, 12]
c_se = [1, 2, 2, 1, 2, 1.5]
d_mean = [12, 10, 8, 6, 4, 2]
d_se = [3, 2, 1, 2, 1, 1]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlabel('X', fontsize = 16)
ax.set_ylabel('Y', fontsize = 16)
plt.axis([0, 7, 0, 30])
x = np.linspace(0, 1)
y = np.linspace(0, 30)
ax.plot(xl, a_mean, linestyle = '-', color = 'k', linewidth = 3, marker = '', label = 'A')
ax.errorbar(xl, a_mean, yerr = a_se, color = 'k', linewidth = 1)
ax.plot(xl, b_mean, linestyle = '--', color = 'k', linewidth = 3, marker = '', label = 'B')
ax.errorbar(xl, b_mean, yerr = b_se, color = 'k', linewidth = 1)
ax.plot(xl, c_mean, linestyle = ':', color = 'k', linewidth = 3, marker = '', label = 'C')
ax.errorbar(xl, c_mean, yerr = c_se, color = 'k', linewidth = 1)
ax.plot(xl, d_mean, linestyle = '-.', color = 'k', linewidth = 3, marker = '', label = 'D')
ax.errorbar(xl, d_mean, yerr = d_se, color = 'k', linewidth = 1)
ax.legend(loc = 0, frameon = False, prop = {'size': 12})
plt.show()
Also, I want to make the error bars to have same line width as for the lines but when I make it thicker, the lines all look the same.
your
errorbar()
should have a
linestyle = ''
else this will draw the line for you.