@@ -31,6 +31,7 @@ def dotHeatmap2d(
3131 colors = None ,
3232 cmap = None ,
3333 max_s = None ,
34+ min_s = None ,
3435 spines = False ,
3536 c_na = 'black' ,
3637 ** kwargs
@@ -98,6 +99,8 @@ def dotHeatmap2d(
9899 r = min (w * 72 / len (col_labels ), h * 72 / len (row_labels ))
99100 # r is the minimal of width and height for each scatter point, unit is point.
100101 max_s = r ** 2
102+ if min_s is None :
103+ min_s = max_s * 0.1
101104 # s
102105 s = kwargs .pop ("s" , None )
103106 # print(s is None,vmin,vmax)
@@ -168,7 +171,7 @@ def dotHeatmap2d(
168171 ax .scatter (
169172 x = df1 .X .values ,
170173 y = df1 .Y .values ,
171- s = df1 .S * max_s ,
174+ s = df1 .S * ( max_s - min_s ) + min_s ,
172175 c = df1 .C .values ,
173176 ** kwargs
174177 ) # vmax=vmax,vmin=vmin,
@@ -189,7 +192,7 @@ def dotHeatmap2d(
189192 ax .scatter (
190193 x = df2 .X .values ,
191194 y = df2 .Y .values ,
192- s = df2 .S * max_s ,
195+ s = df2 .S * ( max_s - min_s ) + min_s ,
193196 c = df2 .C .values ,
194197 ** kwargs
195198 )
@@ -204,7 +207,7 @@ def dotHeatmap2d(
204207 ax .scatter (
205208 x = df1 .X .values ,
206209 y = df1 .Y .values ,
207- s = df1 .S * max_s ,
210+ s = df1 .S * ( max_s - min_s ) + min_s ,
208211 c = df1 .C .values ,
209212 ** kwargs
210213 )
@@ -325,7 +328,7 @@ def __init__(
325328 spines = False ,
326329 grid = 'minor' ,
327330 max_s = None ,
328- min_s = 0.01
331+ min_s = None ,
329332 ** kwargs
330333 ):
331334 # if not hue is None:
@@ -393,8 +396,9 @@ def format_data(self, data, mask=None, z_score=None, standard_scale=None):
393396 raise ValueError ("s must be a str, int or float!" )
394397
395398 if not self .smin is None : #s is a dataframe, perform standard normalization.
399+ # scale to [0,1], then s * (max_size - min_size) + min_size
396400 delta = self .smax - self .smin
397- self .kwargs ["s" ]= self .kwargs ["s" ].applymap (lambda x :max (( x - self .smin )/ delta , self . min_s ) )
401+ self .kwargs ["s" ]= self .kwargs ["s" ].applymap (lambda x :( x - self .smin )/ delta )
398402
399403 # c
400404 if not self .c is None :
@@ -458,12 +462,6 @@ def plot_matrix(self, row_order, col_order):
458462 nrows = len (row_order )
459463 ncols = len (col_order )
460464
461- ratio = self .kwargs .pop ('ratio' ,None )
462- if not ratio is None :
463- print ("Warning: ratio is deprecated, please use max_s instead" )
464- if self .max_s is None :
465- self .max_s = ratio
466-
467465 if self .max_s is None :
468466 # The unit of size for the s parameter is squared points. This means
469467 # that the area of the marker is specified in points squared.
@@ -474,16 +472,21 @@ def plot_matrix(self, row_order, col_order):
474472 self .ax_heatmap .get_window_extent ().width / self .ax_heatmap .figure .dpi ,
475473 self .ax_heatmap .get_window_extent ().height / self .ax_heatmap .figure .dpi ,
476474 ) # unit is inch
477- r = min (w * 72 / self .data2d .shape [1 ], h * 72 / self .data2d .shape [0 ])
475+ r = min (w * 72 / self .data2d .shape [1 ], h * 72 / self .data2d .shape [0 ]) # r = d / 2
478476 # r is the minimal of width and height for each scatter point, unit is point.
479- max_s = r ** 2
477+ self . max_s = r ** 2
480478 if self .verbose >= 1 :
481- print (f"Inferred max_s (max size of scatter point) is: { max_s } " )
479+ print (f"Inferred max_s (max size of scatter point) is: { self . max_s } " )
482480 else :
483- max_s = self .max_s
481+ # max_s = self.max_s
484482 if self .verbose >= 1 :
485- print (f"Using user provided max_s: { max_s } " )
486- self .kwargs ['max_s' ] = max_s
483+ print (f"Using user provided max_s: { self .max_s } " )
484+ if self .min_s is None :
485+ self .min_s = self .max_s * 0.1
486+ # else:
487+ # min_s=self.min_s
488+ self .kwargs ['max_s' ] = self .max_s
489+ self .kwargs ['min_s' ] = self .min_s
487490 self .col_split_gap_pixel = self .col_split_gap * mm2inch * self .ax .figure .dpi
488491 self .wspace = (
489492 (self .col_split_gap_pixel * ncols )
@@ -617,13 +620,21 @@ def collect_legends(self):
617620 # s=self.kwargs.get('s',None)
618621 # colors=self.kwargs.get('colors',None)
619622 markers1 = {}
620- max_s = self .kwargs ['max_s' ]
623+ max_s = self .max_s
624+ min_s = self .min_s
625+ smax = self .smax
626+ smin = self .smin if not self .smin is None else 0
627+ # print(max_s,min_s,smax,smin)
621628 ms = {}
622- for f in [1 , 0.8 , 0.6 , 0.4 , 0.2 ]:
623- k = str (round (f * self .smax , 2 ))
629+ # for f in [1, 0.8, 0.6, 0.4, 0.2]:
630+ # k = str(round(f * self.smax, 2))
631+ # markers1[k] = self.dot_legend_marker
632+ # ms[k] = f * np.sqrt(max_s) * self.alpha
633+ for ratio in np .linspace (1 ,smin / smax ,5 ):
634+ k = str (round (ratio * smax , 2 ))
624635 markers1 [k ] = self .dot_legend_marker
625- ms [k ] = f * np .sqrt (max_s ) * self .alpha
626- # ms[k] = np.sqrt(f * max_s * self.alpha )
636+ ms [k ] = ratio * np .sqrt (max_s ) * self .alpha
637+ print ( ms )
627638 title = self .s if not self .s is None else self .value
628639 self .legend_dict [f"{ title } (dot)" ]= tuple (
629640 [
0 commit comments