我正在尝试生成下面的热图。我已经生成了一个图,但是我需要帮助格式化底部的x轴,以使名称以适当的顺序显示。任何帮助表示赞赏。谢谢!
df = pd.read_table('/srv/data/shared/virus_data.txt', header=None)
df.set_index(0, inplace=True)
df_bgs = df.loc[:, df.isna().any(axis=0)].iloc[3:]
df.dropna(axis=1, inplace=True)
df.sort_values(['Treatment', 'Time'], axis=1, inplace=True)
dfn = df.iloc[3:].astype('float')
dfn.index.name = 'Gene'
col_names = df.loc['Time'] + ' ' + df.loc['Treatment'] + 'HR ' + \
df.loc['Replicate']
dfn.columns = col_names
df.columns = col_names
dfn = dfn.sub(df_bgs.mean(axis=1), axis=0)
dfn[dfn<0] = 0
dfn = dfn.div(dfn.loc['HPRT1'], axis=1)
dfn.drop('HPRT1', axis=0, inplace=True)
dfn = np.log2(dfn+0.01)
treatment2select = ['M', 'M+SNV', 'M+ANDV']
df_ec = dfn.loc[:, df.loc['Treatment'].str.contains('EC')]
df_m = dfn.loc[:, df.loc['Treatment'].isin(treatment2select)]
def row_z_score(df):
return df.sub(df.mean(axis=1), axis=0).div(df.std(axis=1), axis=0)
df_ec = row_z_score(df_ec)
df_m = row_z_score(df_m)
uni_treatment = df.loc['Treatment'].unique()
treatment2color = dict(zip(uni_treatment,sns.color_palette(palette="YlGn",
n_colors=len(uni_treatment))))
col_colors = df.loc['Treatment'].map(treatment2color)
g = sns.clustermap(df_m, col_cluster=True,
col_colors = col_colors,
cmap='RdBu_r', method='ward')
g.ax_col_dendrogram.set_visible(False)