Skip to content

Commit a44f1ba

Browse files
committed
fix bug of legend_hpad in DotClustermapPlotter
1 parent 7c9b9ec commit a44f1ba

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

PyComplexHeatmap/clustermap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,8 @@ class ClusterMapPlotter:
11721172
cbar.dividers.set_color('red')
11731173
cbar.dividers.set_linewidth(2)
11741174
1175-
In addition to vmax,vmin, other parameters will be passed to https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.colorbar.html#matplotlib.figure.Figure.colorbar
1175+
In addition to vmax,vmin, other parameters will be passed to colorbar (https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.colorbar.html#matplotlib.figure.Figure.colorbar)
1176+
or legend (https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.legend.html) depending on the type of legend.
11761177
11771178
plot :bool
11781179
whether to plot or not.

PyComplexHeatmap/dotHeatmap.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,30 @@ def collect_legends(self):
658658
"markers",
659659
]
660660
)
661-
heatmap_label_max_width = (
662-
max([label.get_window_extent().width for label in self.yticklabels])
663-
if len(self.yticklabels) > 0
664-
else 0
665-
)
661+
# Only count yticklabels / ylabel toward the legend offset when they
662+
# are on the same side as the legend (right). Otherwise they don't
663+
# sit between the heatmap and the legend, so they shouldn't push the
664+
# legend further right (this was the cause of legend_hpad appearing
665+
# to have no effect for DotClustermapPlotter).
666+
if len(self.yticklabels) > 0 and self.row_names_side == "right":
667+
max_yticklabel_w = max(
668+
[label.get_window_extent().width for label in self.yticklabels]
669+
)
670+
else:
671+
max_yticklabel_w = 0
672+
if not self.ylabel is None and self.ylabel_side == 'right':
673+
ylabel_w = self.ax.yaxis.label.get_window_extent().width
674+
else:
675+
ylabel_w = 0
676+
if self.row_names_side == self.ylabel_side == 'right':
677+
heatmap_label_max_width = sum([max_yticklabel_w, ylabel_w])
678+
else:
679+
heatmap_label_max_width = max([max_yticklabel_w, ylabel_w])
666680
if (
667681
heatmap_label_max_width >= self.label_max_width
668682
or self.legend_anchor == "ax_heatmap"
669683
):
670-
self.label_max_width = heatmap_label_max_width * 1.1
684+
self.label_max_width = heatmap_label_max_width
671685
self.get_legend_list() #self.legend_list will be created
672686

673687
def post_processing(self):

notebooks/kwargs.ipynb

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)