I want to add vertical lines that depict the residuals of y1_predict - y_true
and y2_predict - y_true
, with red and blue color dash lines, respectively. I would prefer to add lines on top of the current graph, and the code that I can write is shown bellow. Please ignore my code if plotting from scratch is necessary.
import matplotlib.pyplot as plt
x = x_data
ys = [y_true,y1_predict,y2_predict]
labels = ['EMT', 'NN 1st round', 'NN 2nd round']
markers = ['o','s','D']
colors = ['k','r','b']
alphas = [1, 1, 1]
linestyles = ['None','None','None']
fillstyles = ['full','none','none']
plt.figure(figsize=(8, 6), dpi=100, facecolor='w', edgecolor='k')
plt.xlabel("Structure", fontsize=12)
plt.ylabel("Relaxed energy per atom / eV", fontsize=12)
plt.title("NN vs. EMT (low energy region)")
for y, label, marker, color, alpha, linestyle, fillstyle in zip(ys, labels, markers, colors, alphas, linestyles, fillstyles):
plt.plot(x,y, label=label, marker=marker, color=color, alpha=alpha, linestyle=linestyle, fillstyle=fillstyle)
plt.ylim([0.21, 0.25])
plt.legend(loc="lower left",prop={'size': 14})
plt.savefig('nn-emt.png')
Just add the following two lines to your code. This will plot multiple vertical lines at all the points. Since your question is poorly asked, missing a reproducible code, I cannot test it myself.
plt.vlines(x, y1_predict, y_true, color='r')
plt.vlines(x, y2_predict, y_true, color='b')