@@ -27,8 +27,9 @@ def __init__(self, df_size: pd.DataFrame,
2727 self .resized_size_data : pd .DataFrame
2828
2929 @classmethod
30- def parse_from_tidy_data (cls , data_frame : pd .DataFrame , item_key : str , group_key : str ,
31- sizes_key : str , color_key : str , selected_item : Union [None , Sequence ] = None , * ,
30+ def parse_from_tidy_data (cls , data_frame : pd .DataFrame , item_key : str , group_key : str , sizes_key : str ,
31+ color_key : str , selected_item : Union [None , Sequence ] = None ,
32+ selected_group : Union [None , Sequence ] = None , * ,
3233 sizes_func : Union [None , Callable ] = None , color_func : Union [None , Callable ] = None
3334 ):
3435 """
@@ -41,6 +42,8 @@ class method for conveniently constructing DotPlot from tidy data
4142 :param sizes_key:
4243 :param color_key:
4344 :param selected_item: default None, if specified, this should be subsets of `item_key` in `data_frame`
45+ alternatively, this param can be used as self-defined item order definition.
46+ :param selected_group: Same as `selected_item`, for group order and subset groups
4447 :param sizes_func:
4548 :param color_func:
4649 :return:
@@ -50,10 +53,12 @@ class method for conveniently constructing DotPlot from tidy data
5053 data_frame [sizes_key ] = data_frame [sizes_key ].map (sizes_func )
5154 if color_func is not None :
5255 data_frame [color_key ] = data_frame [color_key ].map (color_func )
56+ data_frame = data_frame .pivot (index = item_key , columns = group_key , values = [color_key , sizes_key ])
5357 if selected_item is not None :
54- data_frame = data_frame (data_frame .term_key .isin (selected_item ))
58+ data_frame = data_frame .loc [selected_item , :]
59+ if selected_group is not None :
60+ data_frame = data_frame .loc [:, selected_group ]
5561
56- data_frame = data_frame .pivot (index = item_key , columns = group_key , values = [color_key , sizes_key ])
5762 data_frame .columns = data_frame .columns .map (lambda x : '_' .join (x ))
5863 data_frame = data_frame .fillna (0 )
5964 color_df = data_frame .loc [:, data_frame .columns .str .startswith (color_key )]
0 commit comments