数据示例

代码实例

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 # 绘制分类散点图
 4 
 5 import os
 6 import argparse
 7 import csv
 8 import pandas as pd
 9 import numpy as np
10 import matplotlib.pyplot as plt
11 12 
13 file_path = r'E:\08_cooperation\09_TCReport\医学部数据\NIPT_PGS_190604.xlsx' # 数据路径
14 NIPT_PGS = pd.read_excel(file_path,sheet_name='sub_data',header=0,index_col='SeqID') # 读取数据
15 print(NIPT_PGS.head()) # 查看前6行数据
16 columns = NIPT_PGS.columns # 获取列标签(变量名称),为后续循环使用
17 types = np.unique(NIPT_PGS['Type']) # 获取分类标签,为后续分类循环使用
18 print(len(columns)) # 查看列数
19 print(types) # 查看分类
20 print('running...')
21 for j in range(len(columns)): # 对变量按照变量数目进行循环
22     for i in range(len(types)): # 对分类按照分类数目进行循环
23         plt.scatter(NIPT_PGS.loc[NIPT_PGS['Type']==types[i],'Density(um^2)']
24         ,NIPT_PGS.loc[NIPT_PGS['Type']==types[i],columns[j]]
25         ,s=20
26         ,c=np.array(plt.cm.tab10(i/len(types))).reshape(1,-1)
27         ,label=types[i])
28     plt.legend() # 展示分类标签
29     plt.xlabel('Density(um^2)')
30     plt.ylabel(columns[j])
31     plt.tight_layout() #设置为紧凑型
32     plt.savefig(r'E:\08_cooperation\09_TCReport\医学部数据\%d.png'%(j+1)) # 输出图片
33     plt.close() # 关闭
34 print('finished') # 通知完成

 

posted on 2019-06-04 15:11  caicai2019  阅读(2747)  评论(0编辑  收藏  举报