Skip to content

Commit 0a16206

Browse files
committed
more fixes (2)
1 parent 373d9cc commit 0a16206

20 files changed

+18
-20
lines changed

crawlplot.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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),

plot/overlap.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def plot_similarity_matrix_with_matplotlib(self, data, decimals, title, cell_tex
213213
plt.setp(ax.get_xticklabels(), rotation=45, ha='right', va='top')
214214

215215
# Set title
216-
ax.set_title(title, fontsize=12, fontweight='normal', pad=20, loc='left')
216+
ax.set_title(title, fontsize=self.title_fontsize, fontweight=self.title_fontweight, pad=self.title_pad, loc=self.title_loc)
217217
ax.set_xlabel('')
218218
ax.set_ylabel('')
219219

@@ -237,13 +237,9 @@ def plot_similarity_matrix_with_matplotlib(self, data, decimals, title, cell_tex
237237
ax.spines['left'].set_visible(False)
238238
ax.spines['bottom'].set_visible(False)
239239

240-
# White background
241-
ax.set_facecolor('white')
242-
fig.patch.set_facecolor('white')
243-
244240
# Adjust layout and save
245-
plt.tight_layout()
246-
plt.savefig(img_path, dpi=self.DEFAULT_DPI, bbox_inches='tight', facecolor='white')
241+
plt.tight_layout(pad=self.tight_layout_pad)
242+
plt.savefig(img_path, dpi=self.DEFAULT_DPI, bbox_inches=self.savefig_bbox_inches, facecolor=self.savefig_facecolor)
247243
plt.close()
248244

249245
return fig

plots/crawler/crawldb_status.png

2.22 KB
Loading
1.08 KB
Loading

plots/crawler/metrics.png

-15 Bytes
Loading

plots/crawler/url_protocols.png

558 Bytes
Loading
485 Bytes
Loading
21.7 KB
Loading
26.4 KB
Loading

plots/crawlsize/cumulative.png

2.19 KB
Loading

0 commit comments

Comments
 (0)