@@ -53,39 +53,41 @@ def plot(executable, height=600, grayscale=False, **kwargs):
5353 pass
5454 max_w = sum (max_txt_w ) + (n_cols - 1 ) * txt_spacing
5555 # draw a separator
56- images .append (Image .new (m , (int (.05 * height ), height ), "white" ))
56+ if not kwargs .get ('no_legend' , False ):
57+ images .append (Image .new (m , (int (.05 * height ), height ), "white" ))
5758 # draw a sections plot aside
5859 img = Image .new (m , (s , s ), "white" )
5960 # draw the legend with section names
60- legend = Image .new (m , (max_w , height ), "white" )
61- draw = ImageDraw .Draw (legend )
62- _xy = lambda n , c : (txt_spacing + sum (max_txt_w [:c ]) + len (max_txt_w [:c ]) * txt_spacing , \
63- txt_spacing + (n % n_lab_per_col ) * (txt_spacing + txt_h ))
64- _c_func = [_rgb , _gs ][grayscale ]
65- for i , name , start , end , color in binary :
66- if start != end :
67- x0 , y0 = min (max (ceil (((start / factor ) % s )) - 1 , 0 ), s - 1 ), \
68- min (max (ceil (start / s / factor ) - 1 , 0 ), s - 1 )
69- xN , yN = min (max (ceil (((end / factor ) % s )) - 1 , 0 ), s - 1 ), \
70- min (max (ceil (end / s / factor ) - 1 , 0 ), s - 1 )
71- if y0 == yN :
72- xN = min (max (x0 + 1 , xN ), s - 1 )
73- c = _c_func (color )
74- for x in range (x0 , s if y0 < yN else xN ):
75- img .putpixel ((x , y0 ), c )
76- for y in range (y0 + 1 , yN ):
77- for x in range (0 , s ):
78- img .putpixel ((x , y ), c )
79- if yN > y0 :
80- for x in range (0 , xN ):
81- img .putpixel ((x , yN ), c )
82- # fill the legend with the current section name
83- if name .startswith ("TOTAL" ):
84- color = "black"
85- draw .text (_xy (i , ceil ((i + 1 ) / n_lab_per_col ) - 1 ), name , fill = _c_func (color ), font = font )
86- images .append (img .resize ((int (img .size [0 ] * sf * .2 ), height ), resample = Image .Resampling .BOX ))
87- images .append (Image .new (m , (int (.03 * height ), height ), "white" )) # draw another separator
88- images .append (legend )
61+ if not kwargs .get ('no_legend' , False ):
62+ legend = Image .new (m , (max_w , height ), "white" )
63+ draw = ImageDraw .Draw (legend )
64+ _xy = lambda n , c : (txt_spacing + sum (max_txt_w [:c ]) + len (max_txt_w [:c ]) * txt_spacing , \
65+ txt_spacing + (n % n_lab_per_col ) * (txt_spacing + txt_h ))
66+ _c_func = [_rgb , _gs ][grayscale ]
67+ for i , name , start , end , color in binary :
68+ if start != end :
69+ x0 , y0 = min (max (ceil (((start / factor ) % s )) - 1 , 0 ), s - 1 ), \
70+ min (max (ceil (start / s / factor ) - 1 , 0 ), s - 1 )
71+ xN , yN = min (max (ceil (((end / factor ) % s )) - 1 , 0 ), s - 1 ), \
72+ min (max (ceil (end / s / factor ) - 1 , 0 ), s - 1 )
73+ if y0 == yN :
74+ xN = min (max (x0 + 1 , xN ), s - 1 )
75+ c = _c_func (color )
76+ for x in range (x0 , s if y0 < yN else xN ):
77+ img .putpixel ((x , y0 ), c )
78+ for y in range (y0 + 1 , yN ):
79+ for x in range (0 , s ):
80+ img .putpixel ((x , y ), c )
81+ if yN > y0 :
82+ for x in range (0 , xN ):
83+ img .putpixel ((x , yN ), c )
84+ # fill the legend with the current section name
85+ if name .startswith ("TOTAL" ):
86+ color = "black"
87+ draw .text (_xy (i , ceil ((i + 1 ) / n_lab_per_col ) - 1 ), name , fill = _c_func (color ), font = font )
88+ images .append (img .resize ((int (img .size [0 ] * sf * .2 ), height ), resample = Image .Resampling .BOX ))
89+ images .append (Image .new (m , (int (.03 * height ), height ), "white" )) # draw another separator
90+ images .append (legend )
8991 # combine images horizontally
9092 x , img = 0 , Image .new (m , (sum (i .size [0 ] for i in images ), height ))
9193 for i in images :
0 commit comments