0
votes

I am using the following code to plot three curves (1. mean value, 2. uncertainty/error, and 3. measured data), however, I can't get the desired legends for all the three curves. I could get legends for 'mean' and 'measured data' as blue solid line and red circles, respectively, however, I can't get the blue patch as a legend for 'uncertainty'. I am using Python 2.7 version with Spyder.

qErr = np.std(qArray, axis=1)
h1 = plt.semilogy(T, qArray[:, 2], 'b-', label = 'Mean')
h2 = plt.fill_between(T, qArray[:, 2] - qErr, qArray[:, 2] + qErr, facecolor='b', alpha = 0.2)
plt.hold
h3 = plt.semilogy(T, ORate[idxt0:], 'ro')
plt.legend([h1, h2, h3], ['Mean', 'Uncertainty', 'Measured Data'])
1

1 Answers

0
votes

I got it using @kwarrick hack from here:

qErr = np.std(qArray, axis=1)
h1 = plt.semilogy(T, qArray[:, 2], 'b-', label = 'Mean')
h2 = plt.fill_between(T, qArray[:, 2] - qErr, qArray[:, 2] + qErr, facecolor='b', alpha = 0.2)
h3 = plt.plot([], [], color='blue', linewidth=10)
h4 = plt.semilogy(T, ORate[idxt0:], 'ro')
plt.legend(['Mean', 'Uncertainty', 'Measured Data'])

P.S.: However, I don't understand why I can't get the result if I correspond the legends to their plot handles likes this:

plt.legend([h1, h3, h4], ['Mean', 'Uncertainty', 'Measured Data'])