标签:read 边框 数据 numpy panda 标签 nbsp sub legend
1 import pandas as pd 2 data = pd.read_csv(‘D:/suning/iris.csv‘) 3 data = data.iloc[:,1:] 4 5 ###2维散点图 6 import matplotlib.pyplot as plt 7 8 k=[ 9 ‘Sepal.Length‘, 10 ‘Sepal.Width‘, 11 ‘Petal.Length‘, 12 ‘Petal.Width‘,] 13 for i in k: 14 for m in k: 15 if i != m: 16 plt.figure(figsize=(10,10)) 17 result =data.Species.unique() 18 plt.scatter(data.loc[data.Species == result[2], i], data.loc[data.Species == result[2],m], s = 35, marker=‘*‘, c =‘g‘) 19 plt.scatter(data.loc[data.Species == result[1], i], data.loc[data.Species == result[1],m], s = 35, marker=‘+‘, c =‘r‘) 20 plt.scatter(data.loc[data.Species == result[0], i], data.loc[data.Species == result[0],m], s = 35, marker=‘o‘,c = ‘y‘) 21 # 添加轴标签和标题 22 plt.title( ‘‘) 23 plt.xlabel(i) 24 plt.ylabel(m) 25 # 去除图边框的顶部刻度和右边刻度 26 #lt.tick_params(top = ‘off‘, right = ‘off‘) 27 # 添加图例plt.legend(loc = ‘upper left‘) 28 plt.show() 29 30 ####三维散点图 31 import numpy as np 32 import matplotlib.pyplot as plt 33 from mpl_toolkits.mplot3d import Axes3D 34 35 k=[ 36 ‘Sepal.Length‘, 37 ‘Sepal.Width‘, 38 ‘Petal.Length‘, 39 ‘Petal.Width‘,] 40 for i in k: 41 for m in k: 42 for z in k: 43 if i != m and m!=z and 1!=z: 44 plt.figure(figsize=(10,10)) 45 result = data.Species.unique() 46 ax = plt.subplot(111, projection=‘3d‘) # 创建一个三维的绘图工程 47 ax.scatter(data.loc[data.Species == result[2], i], data.loc[data.Species == result[2], m], data.loc[data.Species == result[2], z], c=‘g‘,marker=‘*‘) # 绘制数据点 48 ax.scatter(data.loc[data.Species == result[1], i], data.loc[data.Species == result[1], m], data.loc[data.Species == result[1], z], c=‘r‘,marker=‘+‘) # 绘制数据点 49 ax.scatter(data.loc[data.Species == result[0], i], data.loc[data.Species == result[0], m], data.loc[data.Species == result[0], z], c=‘y‘,marker=‘o‘) # 绘制数据点 50 ax.set_zlabel(z) # 坐标轴 51 ax.set_ylabel(m) 52 ax.set_xlabel(i) 53 plt.show() 54
标签:read 边框 数据 numpy panda 标签 nbsp sub legend
原文地址:https://www.cnblogs.com/Christina-Notebook/p/10095631.html