python机器学习数据绘图总结

python机器学习数据绘图总结

 

一、matplotlib 绘图

接口文档连接:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter

(1)matplotlib图标正常显示中文

import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif']=['simhei']   #用于正常显示中文标签

plt.rcParams['axes.unicode_minus']=False     #用于正常显示负号

(2)统计作图函数:

  •  plt.plot()绘制线性二维图,折线图

注意:如果向plot()指令提供了一维的数组或者列表,则matplotlib将默认它是一系列的y值,并且自动为其生成x的值。默认的x向量从0开始并且具有和y同样的长度。

  •   plt.bar() 绘制条形图
  •  plt.scatter() 绘制散点图
  • import numpy as np
    from matplotlib import pyplot as plt
    from matplotlib.colors import ListedColormap
    from sklearn.model_selection import train_test_split
    from sklearn.preprocessing import StandardScaler
    from sklearn.datasets import make_moons, make_circles, make_classification
    X, y = make_classification(n_samples=10000,n_features=100, n_redundant=0, n_informative=2,
                               random_state=1, n_clusters_per_class=2,n_classes=2)
    plt.scatter([x[0] for x in X], [x[1] for x in X],c='b', label="train_predict")
    plt.legend(loc="upper right")  # 显示图中的标签
    plt.xlabel("the x")
    # plt.ylabel('value')
    plt.show()
    

      

  •  plt.hist() 绘制二维条形直方图,显示数据的分配情况
  •  plt.pie() 绘制饼图
  •  plt.boxplot() 绘制箱形图

 

posted on 2020-07-06 11:03  lexn  阅读(671)  评论(0编辑  收藏  举报

导航