Skip to content

Commit 94f1820

Browse files
committed
update get_ticklabel_width
1 parent a44f1ba commit 94f1820

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

PyComplexHeatmap/annotations.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,11 +684,24 @@ def plot(self, ax=None, axis=1): # add self.gs,self.fig,self.ax,self.axes
684684
return self.ax
685685

686686
def get_ticklabel_width(self):
687-
hs = [text.get_window_extent().width for text in self.annotated_texts]
688-
if len(hs) == 0:
687+
# Return only the rightward overhang of the annotated texts past the
688+
# right edge of self.ax (in pixels). The annotated texts are placed
689+
# inside the annotation axes, so their full bbox width should NOT be
690+
# treated as horizontal space between the heatmap and the legend
691+
# (that incorrectly inflated label_max_width and made legend_hpad
692+
# appear to have no effect when an anno_label was present on the
693+
# right side of a clustermap / DotClustermapPlotter).
694+
if not self.annotated_texts:
689695
return 0
690-
else:
691-
return max(hs)
696+
try:
697+
ax_right = self.ax.get_window_extent().x1
698+
except Exception:
699+
return 0
700+
overhangs = [
701+
max(0, text.get_window_extent().x1 - ax_right)
702+
for text in self.annotated_texts
703+
]
704+
return max(overhangs) if overhangs else 0
692705

693706

694707
# =============================================================================

notebooks/kwargs.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"import numpy as np\n",
3232
"plt.rcParams['figure.dpi'] = 100\n",
3333
"plt.rcParams['savefig.dpi']=300\n",
34-
"sys.path.append(os.path.expanduser(\"~/Projects/Github/PyComplexHeatmap\"))\n",
34+
"# sys.path.append(os.path.expanduser(\"~/Projects/Github/PyComplexHeatmap\"))\n",
3535
"import PyComplexHeatmap\n",
3636
"print(PyComplexHeatmap.__version__)\n",
3737
"from PyComplexHeatmap import (\n",

0 commit comments

Comments
 (0)