# Python3入门机器学习 - 数据可视化基础matplotlib

2018-02-27 11:14:21来源:https://www.jianshu.com/p/598890122ebc作者:冰源_63ad人点击

``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()``