码迷,mamicode.com
首页 > 编程语言 > 详细

Python 利用循环画散点图

时间:2018-12-10 14:16:19      阅读:406      评论:0      收藏:0      [点我收藏+]

标签: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 

 

Python 利用循环画散点图

标签:read   边框   数据   numpy   panda   标签   nbsp   sub   legend   

原文地址:https://www.cnblogs.com/Christina-Notebook/p/10095631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!