数据集的数据矩阵图(Heatmap)
mport plotly. express as px
import pandas as pd
import matplotlib. pyplot as plt
import seaborn as sns
import numpy as np
from Cython import inline
file_dir= ( "D:\\python\\data\\BLCA_1.txt" )
file_dir2= ( "D:\\python\\data\\BRCA_1.txt" )
file_dir3= ( "D:\\python\\data\\LGG_1.txt" )
file_dir4= ( "D:\\python\\data\\LUSC_1.txt" )
file_dir5= ( "D:\\python\\data\\LUAD_1.txt" )
name= [ ]
data= [ ]
with open ( file_dir2, 'r' ) as f:
for num, line in enumerate ( f) :
if num>= 0 and num < 33000 :
sub_str = line. split( '\t' )
name. append( sub_str[ 0 ] )
num_list_new = [ float ( x) for x in sub_str[ 1 : ] ]
data. append( num_list_new)
fig, ax = plt. subplots( figsize= ( 10 , 1 ) )
sns. heatmap(
data= data,
ax= ax,
fmt= '.1f' ,
)
plt. show( )
直方图
import matplotlib. pyplot as plt
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import palettable
import random
file_dir= ( "D:\\python\\data\\BLCA_1.txt" )
file_dir2= ( "D:\\python\\data\\BRCA_1.txt" )
file_dir3= ( "D:\\python\\data\\LGG_1.txt" )
file_dir4= ( "D:\\python\\data\\LUSC_1.txt" )
file_dir5= ( "D:\\python\\data\\LUAD_1.txt" )
with open ( file_dir, 'r' ) as f:
for num, line in enumerate ( f) :
if num == 0 :
sub_str = line. split( '\t' )
name= sub_str[ 0 ]
num_list_new = [ float ( x) for x in sub_str[ 1 : ] ]
print ( name)
break
print ( line)
print ( num_list_new)
data= num_list_new
n, bins, patches = plt. hist( x= data,
bins= 30 ,
cumulative= False ,
bottom= 0 ,
histtype= 'bar' ,
align= 'mid' ,
orientation= 'vertical' ,
rwidth= 1.0 ,
log= False ,
color= palettable. colorbrewer. qualitative. Dark2_7. mpl_colors[ 3 ] ,
label= "LUSC_" + name,
facecolor= 'black' ,
edgecolor= "black" ,
stacked= False ,
alpha= 0.5
)
plt. xticks( bins)
for patch in patches:
patch. set_facecolor( random. choice( palettable. colorbrewer. qualitative. Dark2_7. mpl_colors) )
plt. plot( bins[ : 30 ] , n, '--' , color= '#2ca02c' )
plt. legend( )
plt. show( )
盒状图
import pandas as pd
import plotly as py
import plotly. graph_objs as go
import numpy as np
import plotly. graph_objects as go
file_dir= ( "D:\\python\\data\\BLCA_1.txt" )
file_dir2= ( "D:\\python\\data\\BRCA_1.txt" )
file_dir3= ( "D:\\python\\data\\LGG_1.txt" )
file_dir4= ( "D:\\python\\data\\LUSC_1.txt" )
file_dir5= ( "D:\\python\\data\\LUAD_1.txt" )
name= [ ]
data= [ ]
with open ( file_dir5, 'r' ) as f:
for num, line in enumerate ( f) :
if num> 0 and num < 11 :
print ( line)
sub_str = line. split( '\t' )
name. append( sub_str[ 0 ] )
num_list_new = [ float ( x) for x in sub_str[ 1 : ] ]
data. append( num_list_new)
x_data = name
y_data = data
colors = [ 'rgba(93, 164, 214, 0.5)' ,
'rgba(155, 144, 14, 0.5)' ,
'rgba(44, 160, 101, 0.5)' ,
'rgba(155, 65, 54, 0.5)' ,
'rgba(27, 114, 255, 0.5)' ,
'rgba(50, 100, 100, 0.5)' ,
'rgba(36, 98, 14, 0.5)' ,
'rgba(200, 50, 255, 0.5)' ,
'rgba(250, 50, 69, 0.5)' ,
'rgba(120, 96, 0, 0.5)' ]
fig = go. Figure( )
for xd, yd, cls in zip ( x_data, y_data, colors) :
fig. add_trace( go. Box(
y= yd,
name= xd,
boxpoints= 'all' ,
jitter= 0.5 ,
fillcolor= cls,
marker_size= 2 ,
line_width= 1 )
)
fig. update_layout(
title= '10组LUAD的RNA基因盒状图' ,
yaxis= dict (
autorange= True ,
showgrid= True ,
zeroline= True ,
dtick= 5 ,
gridcolor= 'rgb(255, 255, 255)' ,
gridwidth= 1 ,
zerolinecolor= 'rgb(255, 255, 255)' ,
zerolinewidth= 2 ,
) ,
margin= dict (
l= 40 ,
r= 30 ,
b= 80 ,
t= 100 ,
) ,
paper_bgcolor= 'rgb(243, 243, 243)' ,
plot_bgcolor= 'rgb(243, 243, 243)' ,
showlegend= True
)
fig. show( )