Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making var_group_rotation work when swap_axes is True #1763

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions scanpy/plotting/_baseplot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,13 +953,13 @@ def _plot_var_groups_brackets(
# verts and codes are used by PathPatch to make the brackets
verts = []
codes = []
if rotation is None and group_labels:
if max([len(x) for x in group_labels]) > 4:
rotation = 90
else:
rotation = 0
if orientation == 'top':
# rotate labels if any of them is longer than 4 characters
if rotation is None and group_labels:
if max([len(x) for x in group_labels]) > 4:
rotation = 90
else:
rotation = 0
for idx, (left_coor, right_coor) in enumerate(zip(left, right)):
verts.append((left_coor, 0)) # lower-left
verts.append((left_coor, 0.6)) # upper-left
Expand All @@ -981,6 +981,7 @@ def _plot_var_groups_brackets(
rotation=rotation,
)
else:
rotation -= 90
top = left
bottom = right
for idx, (top_coor, bottom_coor) in enumerate(zip(top, bottom)):
Expand All @@ -996,16 +997,16 @@ def _plot_var_groups_brackets(

diff = bottom[idx] - top[idx]
group_y_center = top[idx] + float(diff) / 2
if diff * 2 < len(group_labels[idx]):
# cut label to fit available space
group_labels[idx] = group_labels[idx][: int(diff * 2)] + "."
# if diff * 2 < len(group_labels[idx]):
# # cut label to fit available space
# group_labels[idx] = group_labels[idx][: int(diff * 2)] + "."
gene_groups_ax.text(
1.1,
0.8,
group_y_center,
group_labels[idx],
ha='right',
ha='left',
va='center',
rotation=270,
rotation=rotation,
fontsize='small',
)

Expand Down