Skip to content

Commit 44164a8

Browse files
committed
fix clustering and parse bug,fixed #5
1 parent 80f01a4 commit 44164a8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

dotplot/core.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class method for conveniently constructing DotPlot from tidy data
102102
data_frame = data_frame[keys]
103103
_original_item_order = data_frame[item_key].tolist()
104104
_original_item_order = _original_item_order[::-1]
105+
_original_item_order = sorted(set(_original_item_order), key=_original_item_order.index)
105106
if sizes_func is not None:
106107
data_frame[sizes_key] = data_frame[sizes_key].map(sizes_func)
107108
if color_func is not None:
@@ -204,7 +205,7 @@ def __draw_legend(ax, sct: mpl.collections.PathCollection, size_factor, title, c
204205
def __preprocess_data(self, size_factor, cluster_row=False, cluster_col=False, **kwargs):
205206

206207
method = kwargs.get('cluster_method', 'ward')
207-
metric = kwargs.get('cluster_metric', 'eulidean')
208+
metric = kwargs.get('cluster_metric', 'euclidean')
208209
n_clusters = kwargs.get('cluster_n', None)
209210

210211
if cluster_row or cluster_col:
@@ -215,15 +216,15 @@ def __preprocess_data(self, size_factor, cluster_row=False, cluster_col=False, *
215216
else:
216217
_index = cluster_hierarchy(self.size_data, axis=1, method=method,
217218
metric=metric, n_clusters=n_clusters)
218-
for item in self.__slots__:
219-
if hasattr(self, item):
220-
obj_attr = getattr(self, item)
221-
if isinstance(obj_attr, pd.DataFrame):
219+
obj_data = self.__dict__.copy()
220+
for _obj_attr, _obj in obj_data.items():
221+
if not _obj_attr.startswith('__'):
222+
if isinstance(_obj, pd.DataFrame):
222223
if cluster_row:
223-
obj_attr = obj_attr.loc[_index, :]
224+
_obj = _obj.loc[_index, :]
224225
if cluster_col:
225-
obj_attr = obj_attr.loc[:, _index]
226-
setattr(self, item, obj_attr)
226+
_obj = _obj.loc[:, _index]
227+
setattr(self, _obj_attr, _obj)
227228
self.resized_size_data = self.size_data.applymap(func=lambda x: x * size_factor)
228229
if self.circle_data is not None:
229230
self.resized_circle_data = self.circle_data.applymap(func=lambda x: x * size_factor)

0 commit comments

Comments
 (0)