visualize_5_9.py 2.1 KB

1234567891011121314151617181920212223242526272829303132
  1. def hmap(df="dataframe", cmap="seismic", scale=True, dim=(4, 6), rowclus=True, colclus=True, zscore=None, xlabel=True,
  2. ylabel=True, tickfont=(10, 10), r=300, show=False, figtype='png', figname='heatmap', theme=None):
  3. # df = df.set_index(d.columns[0])
  4. # plot heatmap without cluster
  5. # more cmap: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html
  6. if theme == 'dark':
  7. general.dark_bg()
  8. fig, hm = plt.subplots(figsize=dim)
  9. if rowclus and colclus:
  10. hm = sns.clustermap(df, cmap=cmap, cbar=scale, z_score=zscore, xticklabels=xlabel, yticklabels=ylabel,
  11. figsize=dim)
  12. hm.ax_heatmap.set_xticklabels(hm.ax_heatmap.get_xmajorticklabels(), fontsize=tickfont[0])
  13. hm.ax_heatmap.set_yticklabels(hm.ax_heatmap.get_ymajorticklabels(), fontsize=tickfont[1])
  14. general.get_figure(show, r, figtype, figname, theme)
  15. elif rowclus and colclus is False:
  16. hm = sns.clustermap(df, cmap=cmap, cbar=scale, z_score=zscore, xticklabels=xlabel, yticklabels=ylabel,
  17. figsize=dim, row_cluster=True, col_cluster=False)
  18. hm.ax_heatmap.set_xticklabels(hm.ax_heatmap.get_xmajorticklabels(), fontsize=tickfont[0])
  19. hm.ax_heatmap.set_yticklabels(hm.ax_heatmap.get_ymajorticklabels(), fontsize=tickfont[1])
  20. general.get_figure(show, r, figtype, figname, theme)
  21. elif colclus and rowclus is False:
  22. hm = sns.clustermap(df, cmap=cmap, cbar=scale, z_score=zscore, xticklabels=xlabel, yticklabels=ylabel,
  23. figsize=dim, row_cluster=False, col_cluster=True)
  24. hm.ax_heatmap.set_xticklabels(hm.ax_heatmap.get_xmajorticklabels(), fontsize=tickfont[0])
  25. hm.ax_heatmap.set_yticklabels(hm.ax_heatmap.get_ymajorticklabels(), fontsize=tickfont[1])
  26. general.get_figure(show, r, figtype, figname, theme)
  27. else:
  28. hm = sns.heatmap(df, cmap=cmap, cbar=scale, xticklabels=xlabel, yticklabels=ylabel)
  29. plt.xticks(fontsize=tickfont[0])
  30. plt.yticks(fontsize=tickfont[1])
  31. general.get_figure(show, r, figtype, figname, theme)