Skip to content

Commit a5cdb6e

Browse files
committed
update doc, fixed #4, see also commit 1a99ec4
1 parent 1a99ec4 commit a5cdb6e

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

dotplot/annotation_bands.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
module for draw annotation bands.
3-
PS. This implementation mainly refers to the way of seaborn
3+
PS. This implementation mainly refers to the way of seaborn.clustermap
44
"""
55

66
import itertools
@@ -17,6 +17,9 @@
1717

1818
def _process_colors(colors: Union[pd.DataFrame, pd.Series],
1919
index_order: Union[Sequence[Union[str, int]], None] = None):
20+
"""
21+
borrowed from seaborn
22+
"""
2023
if not isinstance(colors, (pd.DataFrame, pd.Series)):
2124
raise TypeError('`colors` should be pandas.DataFrame or pandas.Series')
2225
if index_order is not None:
@@ -37,6 +40,9 @@ def _process_colors(colors: Union[pd.DataFrame, pd.Series],
3740

3841

3942
def _color_list_to_matrix_and_cmap(colors, axis=0):
43+
"""
44+
borrowed from seaborn
45+
"""
4046
if any(issubclass(type(item), list) for item in colors):
4147
all_colors = set(itertools.chain(*colors))
4248
n = len(colors) # number of fields
@@ -62,14 +68,25 @@ def _color_list_to_matrix_and_cmap(colors, axis=0):
6268

6369

6470
def _determine_ticks(labels: Sequence[str]):
71+
"""
72+
center the tick positions
73+
"""
6574
num = len(labels)
6675
return [item + .5 for item in range(num)]
6776

6877

6978
def draw_heatmap(colors: Union[pd.DataFrame, pd.Series],
7079
axes: mpl.axes.Axes, axis=0,
7180
index_order: Union[Sequence[Union[str, int]], None] = None, **kwargs):
72-
# index_order reverse
81+
"""
82+
83+
:param colors: pd.Series or pd.DataFrame
84+
:param axes: matplotlib axes object
85+
:param axis: 0 or 1
86+
:param index_order: the order of colors
87+
:param kwargs: passed to `axes.pcolormesh`
88+
:return:
89+
"""
7390
colors = colors.copy()
7491
if index_order is not None:
7592
index_order = list(index_order)[::-1]
@@ -84,5 +101,7 @@ def draw_heatmap(colors: Union[pd.DataFrame, pd.Series],
84101
axes.set_xticks(_determine_ticks(labels))
85102
axes.set_xticklabels(labels, rotation=90)
86103
_ = axes.set_yticks([])
104+
else:
105+
raise ValueError('axis must be 0 or 1.')
87106
for item in ['left', 'right', 'bottom', 'top']:
88107
axes.spines[item].set_visible(False)

0 commit comments

Comments
 (0)