1

I am trying to generate the heatmap below. I have generated a figure, but I need help formatting the x-axis on the bottom to have the names show up in the appropriate order. Any help is appreciated. Thank You!

Proposed Heatmap

Generated Heatmap

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)
  • Hi, welcome to Stack Overflow. Please see [How to ask](https://stackoverflow.com/help/how-to-ask) and [How to create a MCVE](https://stackoverflow.com/help/mcve). For `pandas`, see [How to ask a good pandas question](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). Here, specifically, can you post a link to `virus_data.txt`? – Evan Dec 07 '18 at 04:57
  • Related? I don't see an `order` param for the axes in `clustermap`s, but I have to think that one exists; or you can sort your `df` before plotting... https://stackoverflow.com/questions/40514921/ordering-boxplot-x-axis-in-seaborn – Evan Dec 07 '18 at 05:08

0 Answers0