Skip to content

Commit 6f67c27

Browse files
authored
Merge pull request #57 from johnramsden/format-plots
Format plots
2 parents 7dc819b + 82f45e1 commit 6f67c27

4 files changed

Lines changed: 79 additions & 40 deletions

File tree

eval/boxplot_wt.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import matplotlib.pyplot as plt
1010
from matplotlib import patches as mpatches
1111
from matplotlib import rcParams
12+
from matplotlib import ticker
1213
import data_cache
1314

14-
# Increase all font sizes by 8 points from their defaults
15-
rcParams.update({key: rcParams[key] + 8 for key in rcParams if "size" in key and isinstance(rcParams[key], (int, float))})
15+
# Increase all font sizes by 16 points from their defaults
16+
rcParams.update({key: rcParams[key] + 16 for key in rcParams if "size" in key and isinstance(rcParams[key], (int, float))})
1617

1718
# ============================================================================
1819
# CONFIGURATION SECTION
@@ -297,16 +298,22 @@ def generate_boxplot(block_dir, zns_dir, output_file, sample_size=None, show_out
297298

298299
# Create boxplot (identical to distribution_comparison_boxplots.py)
299300
if current_data:
301+
# Adjust box width based on number of boxes so they're consistent across subplots
302+
# Base width is 0.8 for 4 boxes, scale proportionally for fewer boxes
303+
num_boxes = len(current_data)
304+
box_width = 0.8 * (num_boxes / 4) if num_boxes > 0 else 0.8
305+
300306
bp = ax.boxplot(current_data,
301307
showfliers=show_outliers,
302-
widths=0.8,
308+
widths=box_width,
303309
medianprops=dict(linewidth=2, color='black'),
304310
patch_artist=True)
305311

306312
# Apply colors and hatches
307313
for i, (box, color, hatch) in enumerate(zip(bp['boxes'], colors, hatches)):
308314
box.set_facecolor(color)
309315
box.set_hatch(hatch)
316+
box.set_hatch_linewidth(3.0)
310317
box.set_alpha(0.7)
311318

312319
# Set x-axis labels (empty for cleaner look)
@@ -319,6 +326,9 @@ def generate_boxplot(block_dir, zns_dir, output_file, sample_size=None, show_out
319326
# Set y-axis label
320327
ax.set_ylabel(metric_label, fontsize=22, weight='bold')
321328

329+
# Use scalar formatter without scientific notation
330+
ax.yaxis.set_major_formatter(ticker.ScalarFormatter(useOffset=False, useMathText=False))
331+
322332
# Rotate y-axis labels
323333
for label in ax.get_yticklabels():
324334
label.set_rotation(45)

eval/distribution_comparison_boxplots.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
from matplotlib import patches as mpatches
1313
from matplotlib.patches import Rectangle
1414
from matplotlib import rcParams
15+
from matplotlib import ticker
16+
from matplotlib.gridspec import GridSpec
1517
import numpy as np
1618
from datetime import datetime, timedelta
1719
import data_cache
1820

19-
# Increase all font sizes by 8 points from their defaults
20-
rcParams.update({key: rcParams[key] + 8 for key in rcParams if "size" in key and isinstance(rcParams[key], (int, float))})
21+
# Increase all font sizes by 16 points from their defaults
22+
rcParams.update({key: rcParams[key] + 16 for key in rcParams if "size" in key and isinstance(rcParams[key], (int, float))})
2123

2224
# ============================================================================
2325
# CONFIGURATION SECTION
@@ -247,14 +249,16 @@ def generate_distribution_comparison(block_dir, zns_dir, distribution, metric, o
247249

248250
print(f"Found {len(block_runs)} block runs and {len(zns_runs)} ZNS runs")
249251

250-
# Create figure with 6 subplots (1 row x 6 columns)
252+
# Create figure with 6 subplots (1 row x 6 columns) using GridSpec for custom widths
251253
# Subplots are 2/5 original height, but all spacing preserved
252254
num_subplots = len(RATIOS) * len(CHUNK_SIZES) # 2 ratios * 3 chunk sizes = 6
253-
fig, axes = plt.subplots(1, num_subplots, figsize=(5 * num_subplots, 5.38))
254255

255-
# Ensure axes is always a list
256-
if num_subplots == 1:
257-
axes = [axes]
256+
# Width ratios: 1077MiB subplots (indices 2 and 5) are half as wide since they have 2 boxes instead of 4
257+
width_ratios = [1, 1, 0.5, 1, 1, 0.5]
258+
259+
fig = plt.figure(figsize=(5 * num_subplots, 5.38))
260+
gs = GridSpec(1, num_subplots, figure=fig, width_ratios=width_ratios)
261+
axes = [fig.add_subplot(gs[0, i]) for i in range(num_subplots)]
258262

259263
# First pass: collect all data to find global maximum for y-axis
260264
all_subplot_data = []
@@ -391,24 +395,37 @@ def generate_distribution_comparison(block_dir, zns_dir, distribution, metric, o
391395

392396
# Create boxplot for this subplot
393397
if current_data:
398+
# Adjust box width based on number of boxes so they're consistent across subplots
399+
# Base width is 0.8 for 4 boxes, scale proportionally for fewer boxes
400+
# Exception: 1077MiB boxes are made thicker since they have fewer boxes
401+
num_boxes = len(current_data)
402+
if chunk_size == 1129316352: # 1077MiB
403+
box_width = 0.8 # Full width like regular boxplots
404+
else:
405+
box_width = 0.8 * (num_boxes / 4) if num_boxes > 0 else 0.8
406+
394407
bp = axes[idx].boxplot(current_data,
395408
showfliers=show_outliers,
396-
widths=0.8,
409+
widths=box_width,
397410
medianprops=dict(linewidth=2, color='black'),
398411
patch_artist=True)
399412

400413
# Apply colors and hatches
401414
for i, (box, color, hatch) in enumerate(zip(bp['boxes'], colors, hatches)):
402415
box.set_facecolor(color)
403416
box.set_hatch(hatch)
417+
box.set_hatch_linewidth(3.0)
404418
box.set_alpha(0.7)
405419

406420
# Set x-axis labels (empty for cleaner look, or could add device labels)
407421
axes[idx].set_xticks(range(1, len(labels) + 1))
408422
axes[idx].set_xticklabels([], rotation=45, fontsize=10)
409423

410424
# Add chunk size label below subplot
411-
axes[idx].set_xlabel(CHUNK_SIZE_LABELS[chunk_size], fontsize=16, weight='bold')
425+
axes[idx].set_xlabel(CHUNK_SIZE_LABELS[chunk_size], fontsize=28, weight='bold')
426+
427+
# Use scalar formatter without scientific notation
428+
axes[idx].yaxis.set_major_formatter(ticker.ScalarFormatter(useOffset=False, useMathText=False))
412429

413430
# Rotate y-axis labels
414431
for label in axes[idx].get_yticklabels():
@@ -425,10 +442,10 @@ def generate_distribution_comparison(block_dir, zns_dir, distribution, metric, o
425442
idx += 1
426443

427444
# Add y-axis label on the far left
428-
fig.text(0.02, 0.5, metric_label, va='center', rotation='vertical', fontsize=22, weight='bold')
445+
fig.text(-0.005, 0.5, metric_label, va='center', rotation='vertical', fontsize=22, weight='bold')
429446

430447
# Adjust layout (do these BEFORE computing positions) - subplots at 2/5 height with proportional spacing
431-
plt.subplots_adjust(wspace=0.05, hspace=0.0)
448+
plt.subplots_adjust(wspace=0.2, hspace=0.0)
432449
plt.tight_layout(pad=0.0)
433450
plt.subplots_adjust(top=0.851, bottom=0.279, left=0.05)
434451

@@ -452,8 +469,8 @@ def generate_distribution_comparison(block_dir, zns_dir, distribution, metric, o
452469
g2_width = g2_right - g2_left
453470

454471
# Vertical placement of the grey boxes in figure coords
455-
box_y = 0.93
456-
box_h = 0.06
472+
box_y = 0.85
473+
box_h = 0.10
457474

458475
# Grey box for Ratio 1:2
459476
fig.add_artist(
@@ -492,7 +509,7 @@ def generate_distribution_comparison(block_dir, zns_dir, distribution, metric, o
492509
"Ratio: 1:2",
493510
ha='center',
494511
va='center',
495-
fontsize=20,
512+
fontsize=26,
496513
weight='bold',
497514
zorder=2,
498515
)
@@ -502,7 +519,7 @@ def generate_distribution_comparison(block_dir, zns_dir, distribution, metric, o
502519
"Ratio: 1:10",
503520
ha='center',
504521
va='center',
505-
fontsize=20,
522+
fontsize=26,
506523
weight='bold',
507524
zorder=2,
508525
)

eval/distribution_comparison_ecdfs.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from datetime import datetime, timedelta
1919
import data_cache
2020

21-
# Increase all font sizes by 8 points from their defaults
22-
rcParams.update({key: rcParams[key] + 8 for key in rcParams if "size" in key and isinstance(rcParams[key], (int, float))})
21+
# Increase all font sizes by 16 points from their defaults
22+
rcParams.update({key: rcParams[key] + 16 for key in rcParams if "size" in key and isinstance(rcParams[key], (int, float))})
2323

2424
# ============================================================================
2525
# CONFIGURATION SECTION
@@ -426,8 +426,10 @@ def generate_distribution_comparison(block_dir, zns_dir, distribution, output_fi
426426
print(f"Warning: No run found for {device} {eviction_type} chunk={chunk_size} dist={distribution} ratio={ratio}")
427427

428428
# Configure subplot
429-
current_ax.set_xlabel(CHUNK_SIZE_LABELS[chunk_size], fontsize=16, weight='bold')
430-
current_ax.set_ylabel('Cumulative Probability (%)', fontsize=18)
429+
current_ax.set_xlabel(CHUNK_SIZE_LABELS[chunk_size], fontsize=28, weight='bold')
430+
if idx == 0:
431+
ylabel = current_ax.set_ylabel('Cumulative Probability (%)', fontsize=25)
432+
ylabel.set_position((-0.1, 0.3))
431433
current_ax.set_ylim(0, 100)
432434

433435
# Configure x-axis scale
@@ -457,7 +459,6 @@ def exp_formatter(x, pos):
457459

458460
current_ax.xaxis.set_major_formatter(FuncFormatter(exp_formatter))
459461
else:
460-
current_ax.set_xlim(left=0)
461462
# Use MaxNLocator to ensure nice, evenly-spaced tick intervals
462463
current_ax.xaxis.set_major_locator(MaxNLocator(nbins=6, integer=False, prune=None))
463464

@@ -496,13 +497,13 @@ def exp_formatter(x, pos):
496497
Line2D([0], [0], color='#f781bf', linestyle='--', linewidth=LINE_WIDTH,
497498
label='Block (Chunk LRU)', alpha=0.8),
498499
]
499-
fig.legend(ncols=4, handles=legend_lines, bbox_to_anchor=(subplot_center, 0.02),
500+
fig.legend(ncols=4, handles=legend_lines, bbox_to_anchor=(subplot_center, -0.09),
500501
loc='center', fontsize="large", columnspacing=2.0, frameon=False)
501502

502503
# Add a background box for the x-axis label to make it stand out
503-
label_y = 0.08
504-
label_width = 0.12
505-
label_height = 0.04
504+
label_y = 0.01
505+
label_width = 0.18
506+
label_height = 0.08
506507
fig.add_artist(
507508
Rectangle(
508509
(subplot_center - label_width/2, label_y - label_height/2),
@@ -518,7 +519,7 @@ def exp_formatter(x, pos):
518519

519520
# Add x-axis label at the bottom, centered over the subplots
520521
fig.text(subplot_center, label_y, 'Latency (ms)', ha='center', va='center',
521-
fontsize=18, weight='bold', zorder=11)
522+
fontsize=30, weight='bold', zorder=11)
522523

523524
# First 3 subplots -> Ratio 1:2, next 3 -> Ratio 1:10
524525
group1 = axes_bboxes[0:3]
@@ -534,8 +535,8 @@ def exp_formatter(x, pos):
534535
g2_width = g2_right - g2_left
535536

536537
# Vertical placement of the grey boxes in figure coords
537-
box_y = 0.93
538-
box_h = 0.06
538+
box_y = 0.85
539+
box_h = 0.10
539540

540541
# Grey box for Ratio 1:2
541542
fig.add_artist(
@@ -574,7 +575,7 @@ def exp_formatter(x, pos):
574575
"Ratio: 1:2",
575576
ha='center',
576577
va='center',
577-
fontsize=20,
578+
fontsize=26,
578579
weight='bold',
579580
zorder=2,
580581
)
@@ -584,7 +585,7 @@ def exp_formatter(x, pos):
584585
"Ratio: 1:10",
585586
ha='center',
586587
va='center',
587-
fontsize=20,
588+
fontsize=26,
588589
weight='bold',
589590
zorder=2,
590591
)

eval/ecdf_wt.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import numpy as np
1515
import data_cache
1616

17-
# Increase all font sizes by 8 points from their defaults
18-
rcParams.update({key: rcParams[key] + 8 for key in rcParams if "size" in key and isinstance(rcParams[key], (int, float))})
17+
# Increase all font sizes by 16 points from their defaults
18+
rcParams.update({key: rcParams[key] + 16 for key in rcParams if "size" in key and isinstance(rcParams[key], (int, float))})
1919

2020
# ============================================================================
2121
# CONFIGURATION SECTION
@@ -402,8 +402,8 @@ def generate_ecdf(block_dir, zns_dir, output_file, metric_type="get_total", samp
402402
print(f"Warning: No run found for {device} {eviction_type}")
403403

404404
# Configure subplot
405-
# ax.set_xlabel("64KiB", fontsize=16, weight='bold')
406-
ax.set_ylabel('Cumulative Probability (%)', fontsize=18)
405+
# ax.set_xlabel("64KiB", fontsize=28, weight='bold')
406+
ax.set_ylabel('Cumulative Probability (%)', fontsize=25)
407407
ax.set_ylim(0, 100)
408408

409409
# Configure x-axis scale
@@ -433,7 +433,6 @@ def exp_formatter(x, pos):
433433

434434
ax.xaxis.set_major_formatter(FuncFormatter(exp_formatter))
435435
else:
436-
ax.set_xlim(left=0)
437436
# Use MaxNLocator to ensure nice, evenly-spaced tick intervals
438437
ax.xaxis.set_major_locator(MaxNLocator(nbins=6, integer=False, prune=None))
439438

@@ -465,14 +464,26 @@ def exp_formatter(x, pos):
465464
Line2D([0], [0], color='#f781bf', linestyle='--', linewidth=LINE_WIDTH,
466465
label='Block (Chunk LRU)', alpha=0.8),
467466
]
468-
fig.legend(ncols=4, handles=legend_lines, bbox_to_anchor=(subplot_center, 0.02),
467+
fig.legend(ncols=4, handles=legend_lines, bbox_to_anchor=(subplot_center, -0.09),
469468
loc='center', fontsize="large", columnspacing=2.0, frameon=False)
470469

471470
# Add a background box for the x-axis label to make it stand out
472-
label_y = 0.08
471+
label_y = 0.01
472+
label_width = 0.18
473+
label_height = 0.08
474+
fig.add_artist(
475+
Rectangle(
476+
(subplot_center - label_width/2, label_y - label_height/2),
477+
label_width,
478+
label_height,
479+
facecolor='white',
480+
edgecolor='none',
481+
zorder=10,
482+
)
483+
)
473484
# Add x-axis label at the bottom, centered over the subplot
474485
fig.text(subplot_center, label_y, 'Latency (ms)', ha='center', va='center',
475-
fontsize=18, weight='bold', zorder=11)
486+
fontsize=30, weight='bold', zorder=11)
476487

477488
# Save figure
478489
plt.savefig(output_file, bbox_inches='tight', dpi=100)

0 commit comments

Comments
 (0)