@@ -21,7 +21,7 @@ class CrawlPlot:
2121 DEFAULT_FIGSIZE = 7
2222 DEFAULT_DPI = 300
2323
24- title_fontsize = 14
24+ title_fontsize = 15
2525 title_pad = 20
2626 title_fontweight = "normal"
2727 title_loc = "left"
@@ -216,6 +216,15 @@ def nice_tick_step(vmin, vmax, n=5):
216216 nice_frac = 1 if frac <= 1 else 2 if frac <= 2 else 5 if frac <= 5 else 10
217217 return nice_frac * 10 ** exp
218218
219+ @staticmethod
220+ def center_legend_title (fig , ax , leg_items , leg_title , x_axes = 0.1 ):
221+ fig .canvas .draw ()
222+ r = fig .canvas .get_renderer ()
223+ bb = leg_items .get_window_extent (r )
224+ y = fig .transFigure .inverted ().transform ((0 , (bb .y0 + bb .y1 )/ 2 ))[1 ]
225+ x = fig .transFigure .inverted ().transform (ax .transAxes .transform ((x_axes , 0 )))[0 ]
226+ leg_title .set_bbox_to_anchor ((x , y ), transform = fig .transFigure )
227+
219228 def line_plot_with_matplotlib (
220229 self ,
221230 data ,
@@ -332,18 +341,8 @@ def line_plot_with_matplotlib(
332341 num_legend_items = len (groups )
333342 ncol = 5 if num_legend_items == 5 else 4
334343
335- # legend = ax.legend(
336- # loc="upper center",
337- # bbox_to_anchor=(0.5, -0.1),
338- # ncol=ncol,
339- # frameon=False,
340- # fontsize=self.legend_fontsize,
341- # title=clabel,
342- # title_fontsize=self.legend_title_fontsize,
343- # )
344-
345-
346344 if clabel :
345+ # legend title is side-by-side with legend items
347346 leg_items = ax .legend (
348347 loc = "upper center" ,
349348 ncol = ncol ,
@@ -356,13 +355,16 @@ def line_plot_with_matplotlib(
356355 [],
357356 title = clabel ,
358357 loc = "upper center" ,
359- bbox_to_anchor = (0.25 , - 0.1 ),
358+ bbox_to_anchor = (0.2 , - 0.075 ),
360359 frameon = False ,
361360 title_fontsize = self .legend_title_fontsize ,
362361 )
363362
364363 ax .add_artist (leg_items )
364+
365+ # self.center_legend_title(fig=fig, ax=ax, leg_items=leg_items, leg_title=leg_title)
365366 else :
367+ # no legend title
366368 legend_items = ax .legend (
367369 loc = "upper center" ,
368370 bbox_to_anchor = (0.5 , - 0.1 ),
0 commit comments