本文共 1034 字,大约阅读时间需要 3 分钟。
plt.plot(x,siny,label="sin(x)")plt.plot(x,cosy,color="red",linestyle="--",label="cos(x)")plt.axis([-2,12,-2,2]) //设置横纵坐标范围,也可以使用 plt.xlim(-2,12) plt.ylim(-2,2)来设置plt.xlabel("x axis")plt.ylabel("y value")plt.legend()plt.title("Hello Machine Learning!")plt.show()
散点图一般用于绘制二维特征,即横纵两个轴都是特征
x = np.random.normal(0,1,10000)y = np.random.normal(0,1,10000)plt.scatter(x,y,alpha=0.3)plt.show()
import numpy as npimport matplotlib.pyplot as pltfrom sklearn import datasetsiris = datasets.load_iris()iris.keys()data = iris['data']target = iris['target']plt.scatter(data[target==0,0],data[target==0,1],color="red")plt.scatter(data[target==1,0],data[target==1,1],color="green",marker='+')plt.scatter(data[target==2,0],data[target==2,1],color="blue",marker='x')plt.show()
plt.scatter(data[target==0,2],data[target==0,3],color="red")plt.scatter(data[target==1,2],data[target==1,3],color="green",marker='+')plt.scatter(data[target==2,2],data[target==2,3],color="blue",marker='x')plt.show()
转载地址:http://tfoso.baihongyu.com/