1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import matplotlib.pyplot as plt import numpy as np
x = np.linspace(-2, 3, 50) y1 = x**2 y2 = 2*x plt.figure() l1, = plt.plot(x,y1,label = 'square line') l2, = plt.plot(x, y2, color='red', linewidth=1.0, linestyle='--',label='linear line')
plt.xlim((-1, 2)) plt.ylim((-2, 3))
ax = plt.gca()
ax.spines['right'].set_color('none') ax.spines['top'].set_color('none')
ax.spines['bottom'].set_position(('data', 0))
ax.spines['left'].set_position(('data',0))
plt.legend(handles=[l1, l2], labels=['hmm', 'wtf'], loc='best') plt.show()
|