我想在我的seaborn热图中添加自定义y刻度。第一个是默认选项,但是当我添加ticks
时他们一路走到顶端:
yticklabels = []
for i in range(25):
yticklabels.append(str(i) + "Mb")
ax = sns.heatmap(result, cmap=cmap, yticklabels = yticklabels)
还尝试以这种方式添加yticks,但标签也贴在顶部
yticklabels,yticks = [], []
for i in range(45):
yticklabels.append(str(i) + "Mb")
yticks.append(i)
ax = sns.heatmap(result, cmap=cmap, yticklabels = yticklabels)
ax.yticks = yticks
所以完整的例子并不那么容易,但在这里:
for k, chromosome in df_genome.iterrows():
df_chromosome = df_blast[(df_blast.sseqid == chromosome.seqname)]
print chromosome.seqname
print(len(df_chromosome))
for i in range(0, chromosome.end, args.step):
start = i
end = i + args.step
if end > chromosome.end:
continue
# start = chromosome.end - args.step
# end = chromosome.end + 1
#print start, end
hits_count = len(df_chromosome[(df_chromosome.sstart >= start) & (df_chromosome.sstart <= end) & (df_chromosome.pident >= 80)])
if hits_count > max_hits_count:
max_chr_start = start
max_chr_end = end
max_chr = chromosome.seqname
max_hits_count = hits_count
print '->',chromosome.seqname,max_hits_count
#print(chromosome.seqname, start, end, hits_count)
position = start / 1000000.0
result.append( [chromosome.seqname,position, hits_count] )
#print result
df = pd.DataFrame(result)
df.columns = ['chromosome','position','hits']
result = pd.pivot_table(data=df,
index='position',
values='hits',
columns='chromosome')
#This is where I am stucked
yticklabels = []
for i in range(45):
yticklabels.append(str(i) + "Mb")
ax = sns.heatmap(result, cmap=cmap,yticklabels=7)