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

fix bar_label_kwargs so rotation works #240

Open
wants to merge 1 commit into
base: master
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
9 changes: 5 additions & 4 deletions calour/heatmap/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ def _ax_bar(ax, values, colors=None, width=0.3, position=0, label=True, label_kw
label_kwargs = {}
kwargs = {'color': 'w', 'weight': 'bold', 'size': 6,
'ha': 'center', 'va': 'center'}
if axis == 0:
kwargs['rotation'] = 0
else:
kwargs['rotation'] = 90
kwargs.update(label_kwargs)

# convert to string and leave it as empty if it is None
Expand All @@ -428,12 +432,10 @@ def _ax_bar(ax, values, colors=None, width=0.3, position=0, label=True, label_kw
# plot the color bar along x axis
pos = prev - offset, position
w, h = i - prev, width
rotation = 0
else:
# plot the color bar along y axis
pos = position, prev - offset
w, h = width, i - prev
rotation = 90
rect = mpatches.Rectangle(
pos, # position
w, # width (size along x axis)
Expand All @@ -448,8 +450,7 @@ def _ax_bar(ax, values, colors=None, width=0.3, position=0, label=True, label_kw
cy = ry + rect.get_height() / 2.0

# add the text in the color bars
ax.annotate(value, (cx, cy), rotation=rotation,
**kwargs)
ax.annotate(value, (cx, cy), **kwargs)

prev = i

Expand Down