how to change legend labels in matplotlib code example
Example 1: matplotlib add legend axis x
fig = plt.figure(figsize=(10,5))
ax = fig.add_subplot(111)
ax.set_title('ADR vs Rating (CS:GO)')
ax.scatter(x=data[:,0],y=data[:,1],label='Data')
plt.plot(data[:,0], m*data[:,0] + b,color='red',label='Our Fitting
Line')
ax.set_xlabel('ADR')
ax.set_ylabel('Rating')
ax.legend(loc='best')
plt.show()
Example 2: python how to add a figure legend at the best position
import matplotlib.pyplot as plt
x1 = [1, 2, 3]
y1 = [4, 5, 6]
x2 = [1, 3, 5]
y2 = [6, 5, 4]
plt.plot(x1, y1, label="Dataset_1")
plt.plot(x2, y2, label="Dataset_2")
plt.legend(loc='best')
plt.show()
Location String Location Code (e.g. loc=1)
'best' 0
'upper right' 1
'upper left' 2
'lower left' 3
'lower right' 4
'right' 5
'center left' 6
'center right' 7
'lower center' 8
'upper center' 9
'center' 10