From 4e3b361cdf574dde7b72e8449d8f14f6c68e15c8 Mon Sep 17 00:00:00 2001 From: Qing <44231502+byemaxx@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:21:49 -0400 Subject: [PATCH] - Change: Optimized the x-axis and y-axis labels of the heatmap plot to make the labels more clear. --- Docs/ChangeLog.md | 6 +++++ metax/taxafunc_ploter/heatmap_plot.py | 35 +++++++++++++++++++-------- metax/utils/version.py | 2 +- pyproject.toml | 2 +- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Docs/ChangeLog.md b/Docs/ChangeLog.md index dfd8f56..bfe5f69 100644 --- a/Docs/ChangeLog.md +++ b/Docs/ChangeLog.md @@ -1,3 +1,9 @@ +# Version: 1.111.5 +## Date: 2024-08-21 +### Changes: +- Change: Optimized the x-axis and y-axis labels of the heatmap plot to make the labels more clear. + + # Version: 1.111.4 ## Date: 2024-08-21 ### Changes: diff --git a/metax/taxafunc_ploter/heatmap_plot.py b/metax/taxafunc_ploter/heatmap_plot.py index a47ba35..cf5c5b2 100644 --- a/metax/taxafunc_ploter/heatmap_plot.py +++ b/metax/taxafunc_ploter/heatmap_plot.py @@ -25,6 +25,21 @@ def __init__(self, tfobj, linkage_method:str = 'average', distance_metric:str = # reset sns style sns.set_theme() plt.style.use('default') + + def get_x_labels_ha(self): + x_rotation = self.x_labels_rotation + if x_rotation > 0: + return 'right' + elif x_rotation < 0: + return 'left' + else: + return 'center' + def get_y_labels_va(self): + y_rotation = self.y_labels_rotation + if y_rotation >= 0: + return 'baseline' + else: + return 'top' def rename_taxa(self, df): first_index = df.index[0] @@ -150,14 +165,14 @@ def plot_top_taxa_func_heatmap_of_test_res(self, df, top_number:int|str= 100, fig.ax_heatmap.get_xmajorticklabels(), fontsize=font_size, rotation=self.x_labels_rotation, - ha = 'right' if self.x_labels_rotation > 0 else 'left' + ha = self.get_x_labels_ha() ) fig.ax_heatmap.set_yticklabels( fig.ax_heatmap.get_ymajorticklabels(), fontsize=font_size, rotation=self.y_labels_rotation, ha = 'left', - va = 'baseline' if self.y_labels_rotation > 0 else 'top' + va = self.get_y_labels_va() ) cbar = fig.ax_heatmap.collections[0].colorbar @@ -296,14 +311,14 @@ def plot_basic_heatmap_of_test_res(self, df, top_number:int = 100, value_type:st fig.ax_heatmap.get_xmajorticklabels(), fontsize=font_size, rotation=self.x_labels_rotation, - ha = 'right' if self.x_labels_rotation > 0 else 'left' + ha = self.get_x_labels_ha() ) fig.ax_heatmap.set_yticklabels( fig.ax_heatmap.get_ymajorticklabels(), fontsize=font_size, rotation=self.y_labels_rotation, ha = 'left', - va = 'baseline' if self.y_labels_rotation > 0 else 'top' + va = self.get_y_labels_va() ) scale_title = f", scaled by {scale}" if scale in ['row', 'column', 'all'] else '' @@ -396,14 +411,14 @@ def plot_basic_heatmap(self, df, title = 'Heatmap',fig_size:tuple|None = None, fig.ax_heatmap.get_xmajorticklabels(), fontsize=font_size, rotation=self.x_labels_rotation, - ha="right" if self.x_labels_rotation > 0 else "left", + ha=self.get_x_labels_ha() ) fig.ax_heatmap.set_yticklabels( fig.ax_heatmap.get_ymajorticklabels(), fontsize=font_size, rotation=self.y_labels_rotation, ha="left", - va="baseline" if self.y_labels_rotation > 0 else "top", + va=self.get_y_labels_va() ) title = f"{title} (scaled by {scale})" if scale not in [None, 'None'] else title plt.suptitle(title, weight='bold') @@ -556,14 +571,14 @@ def plot_heatmap_of_all_condition_res(self, df, pvalue:float = 0.05,scale:str|N fig.ax_heatmap.get_xmajorticklabels(), fontsize=font_size, rotation=self.x_labels_rotation, - ha = 'right' if self.x_labels_rotation > 0 else 'left' + ha = self.get_x_labels_ha() ) fig.ax_heatmap.set_yticklabels( fig.ax_heatmap.get_ymajorticklabels(), fontsize=font_size, rotation=self.y_labels_rotation, ha = 'left', - va = 'baseline' if self.y_labels_rotation > 0 else 'top' + va = self.get_y_labels_va() ) if res_df_type == 'deseq2': title = f"The Heatmap of log2FoldChange calculated by DESeq2 ({p_type} <= {pvalue}, {log2fc_min} <= log2fc <= {log2fc_max}, scaled by {scale})" @@ -694,14 +709,14 @@ def plot_heatmap_of_dunnett_test_res(self, df, pvalue:float = 0.05,scale:str|No fig.ax_heatmap.get_xmajorticklabels(), fontsize=font_size, rotation=self.x_labels_rotation, - ha = 'right' if self.x_labels_rotation > 0 else 'left' + ha = self.get_x_labels_ha() ) fig.ax_heatmap.set_yticklabels( fig.ax_heatmap.get_ymajorticklabels(), fontsize=font_size, rotation=self.y_labels_rotation, ha = 'left', - va = 'baseline' if self.y_labels_rotation > 0 else 'top' + va = self.get_y_labels_va() ) plt.suptitle(f"The Heatmap of t-statistic calculated by Dunnett test (p-value < {pvalue}, scaled by {scale})", weight='bold') diff --git a/metax/utils/version.py b/metax/utils/version.py index 8885c27..89c504f 100644 --- a/metax/utils/version.py +++ b/metax/utils/version.py @@ -1,2 +1,2 @@ -__version__ = '1.111.4' +__version__ = '1.111.5' API_version = '2' \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d1fc40b..2eeba7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "MetaXTools" -version = "1.111.4" +version = "1.111.5" description = "MetaXTools is a novel tool for linking peptide sequences with taxonomic and functional information in Metaproteomics." readme = "README_PyPi.md" license = { text = "NorthOmics" }