让你优雅的画出散点分布图,还是二合一哦 ^ _ ^
啥也不说,想让你看看效果吧。
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocato
input_file_M = 'M_TET.tsv'
with open (input_file_M) as f_input:
data_raw_M = f_input.read().strip('\n').split('\n')
data_M = [[float(j) for j in i.split('\t')[1:]] for i in data_raw_M]
label_M = [i.split('\t')[0] for i in data_raw_M]
input_file_T = 'T_TET.tsv'
with open (input_file_T) as f_input:
data_raw_T = f_input.read().strip('\n').split('\n')
data_T = [[float(j) for j in i.split('\t')[1:]] for i in data_raw_T]
label_T = [i.split('\t')[0] for i in data_raw_T]
plt.figure(figsize=(20,5), dpi=500)
out_file = 'merge_scatter.jpg'
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none') # 设置右‘脊梁’为无色
ax.spines['top'].set_color('none')
plt.subplot(1, 2, 1)
for i in range(len(data_M)):
plt.scatter([i for num in range(len(data_M[i]))],data_M[i], s=200)
# 中位数
plt.scatter(i,np.median(data_M[i]), marker='_' ,c='black', s=900)
plt.xticks(range(len(label_M)), label_M, fontsize=10)
plt.xlabel('TET', fontsize=10)
plt.ylabel('M', fontsize=10)
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none') # 设置右‘脊梁’为无色
ax.spines['top'].set_color('none')
ax.set_ylim(0, 50)
plt.subplot(1, 2, 2)
for i in range(len(data_T)):
plt.scatter([i for num in range(len(data_T[i]))],data_T[i], s=200)
plt.scatter(i,np.median(data_T[i]), marker='_' ,c='black', s=900)
plt.xticks(range(len(label_T)),label_T)
plt.xlabel('TET', fontsize=10)
plt.ylabel('T', fontsize=10)
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none') # 设置右‘脊梁’为无色
ax.spines['top'].set_color('none')
#plt.savefig(out_file, dpi=500)
plt.show()