1. 程式人生 > >plt.legend( )函式,給影象加上圖例。

plt.legend( )函式,給影象加上圖例。

import  tensorflow as tf
from matplotlib import pyplot as plt
import numpy as np

train_x = np.linspace(-1, 1, 100)
train_y_1 = 2*train_x + np.random.rand(*train_x.shape)*0.3
train_y_2 = train_x**2+np.random.randn(*train_x.shape)*0.3

plt.scatter(train_x, train_y_1, c='red', marker='v' )
plt.scatter(train_x, train_y_2, c='blue', marker='o' )
plt.legend(["red","Blue"])
plt.show()

plt.legend()函式主要的作用就是給圖加上圖例,plt.legend([x,y,z])裡面的引數使用的是list的的形式將圖表的的名稱餵給這和函式。