Skip to content

Commit c130564

Browse files
committed
fix bug when circle is donot needed
1 parent b901925 commit c130564

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

dotplot/core.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class DotPlot(object):
1717
DEFAULT_ITEM_WIDTH = 0.3
1818
DEFAULT_LEGENDS_WIDTH = .45
1919
MIN_FIGURE_HEIGHT = 3
20+
DEFAULT_BAND_ITEM_LENGTH = DEFAULT_ITEM_HEIGHT
2021

2122
def __init__(self, df_size: pd.DataFrame,
2223
df_color: Union[pd.DataFrame, None] = None,
2324
df_circle: Union[pd.DataFrame, None] = None,
25+
df_annotation: Union[pd.DataFrame, None] = None,
2426
):
2527
"""
2628
Construction a `DotPlot` object from `df_size` and `df_color`
@@ -30,23 +32,32 @@ def __init__(self, df_size: pd.DataFrame,
3032
"""
3133
__slots__ = ['size_data', 'resized_size_data',
3234
'color_data', 'height_item', 'width_item',
33-
'circle_data', 'resized_circle_data'
35+
'circle_data', 'resized_circle_data', 'annotation_data'
3436
]
35-
if (df_color is not None) & (df_size.shape != df_color.shape):
37+
if df_color is not None and df_size.shape != df_color.shape:
3638
raise ValueError('df_size and df_color should have the same dimension')
39+
if df_circle is not None and df_size.shape != df_circle.shape:
40+
raise ValueError('df_size and df_circle should have the same dimension')
41+
if df_annotation is not None and df_size.shape != df_annotation.shape:
42+
raise ValueError('df_size and df_annotation should have the same row number')
43+
3744
self.size_data = df_size
3845
self.color_data = df_color
3946
self.circle_data = df_circle
4047
self.height_item, self.width_item = df_size.shape
41-
self.resized_size_data: pd.DataFrame
42-
self.resized_circle_data: pd.DataFrame
48+
self.annotation_data = df_annotation
49+
self.resized_size_data: Union[pd.DataFrame, None] = None
50+
self.resized_circle_data: Union[pd.DataFrame, None] = None
4351

4452
def __get_figure(self):
4553
_text_max = math.ceil(self.size_data.index.map(len).max() / 15)
4654
mainplot_height = self.height_item * self.DEFAULT_ITEM_HEIGHT
4755
mainplot_width = (
4856
(_text_max + self.width_item) * self.DEFAULT_ITEM_WIDTH
4957
)
58+
if self.annotation_data is not None:
59+
pass
60+
5061
figure_height = max([self.MIN_FIGURE_HEIGHT, mainplot_height])
5162
figure_width = mainplot_width + self.DEFAULT_LEGENDS_WIDTH
5263
plt.style.use('seaborn-white')
@@ -102,7 +113,7 @@ class method for conveniently constructing DotPlot from tidy data
102113
data_frame.columns = data_frame.columns.map(lambda x: '_'.join(x))
103114
data_frame = data_frame.fillna(0)
104115

105-
sizes_df, color_df, circle_df = (None, None, None)
116+
sizes_df, color_df, circle_df = None, None, None
106117
sizes_df = data_frame.loc[:, data_frame.columns.str.startswith(sizes_key)]
107118
if color_key is not None:
108119
color_df = data_frame.loc[:, data_frame.columns.str.startswith(color_key)]
@@ -114,7 +125,8 @@ def __get_coordinates(self, size_factor):
114125
X = list(range(1, self.width_item + 1)) * self.height_item
115126
Y = sorted(list(range(1, self.height_item + 1)) * self.width_item)
116127
self.resized_size_data = self.size_data.applymap(func=lambda x: x * size_factor)
117-
self.resized_circle_data = self.circle_data.applymap(func=lambda x: x * size_factor)
128+
if self.circle_data is not None:
129+
self.resized_circle_data = self.circle_data.applymap(func=lambda x: x * size_factor)
118130
return X, Y
119131

120132
def __draw_dotplot(self, ax, size_factor, cmap, vmin, vmax):
@@ -200,6 +212,8 @@ def plot(self, size_factor: float = 15,
200212
self.__draw_legend(ax_sizes, scatter, size_factor, title='Sizes', color='#58000C')
201213
if sct_circle is not None:
202214
self.__draw_legend(ax_circles, sct_circle, size_factor, title='Circles', circle=True, color='k')
215+
else:
216+
ax_circles.axis('off')
203217
self.__draw_color_bar(ax_cbar, scatter, cmap, vmin, vmax)
204218
if path:
205219
fig.savefig(path, dpi=300, bbox_inches='tight') #

0 commit comments

Comments
 (0)