openhands openhands commited on
Commit
4a4a7b5
·
1 Parent(s): 46ff970

Method C: Use domain coordinates for layout images with log scale

Browse files

Layout images don't work correctly with log scale axes when using data
coordinates (xref='x'). The solution is to use domain coordinates
(xref='x domain') which represent positions as fractions (0-1) of the
plot area.

This requires:
1. Manually calculating the log10 position of each point
2. Converting to domain coordinates relative to the axis range
3. Setting explicit axis ranges that match the domain calculations

Tested locally - colored circles now align perfectly with scatter markers.

Co-authored-by: openhands <openhands@all-hands.dev>

Files changed (1) hide show
  1. leaderboard_transformer.py +38 -14
leaderboard_transformer.py CHANGED
@@ -570,7 +570,20 @@ def _plot_scatter_plotly(
570
  ))
571
 
572
  # Add company logo images for each data point
573
- # Note: With log scale, Plotly layout images use raw data values (same as scatter traces)
 
 
 
 
 
 
 
 
 
 
 
 
 
574
  for _, row in data_plot.iterrows():
575
  model_name = row.get('Language Model', '')
576
  company_info = get_company_from_model_name(model_name)
@@ -584,20 +597,31 @@ def _plot_scatter_plotly(
584
  logo_uri = f"data:image/svg+xml;base64,{encoded_logo}"
585
 
586
  x_val = row[x_col_to_use]
 
 
 
 
 
 
 
 
 
587
 
588
- # Calculate logo size - use percentage of data range
589
- # For log scale, size is in data units (will be log-scaled by Plotly)
590
- logo_size_x = max_reported_cost * 0.08 if max_reported_cost > 0 else 0.3
591
- logo_size_y = 2.5 # Fixed y size in data units
 
 
592
 
593
  layout_images.append(dict(
594
  source=logo_uri,
595
- xref="x",
596
- yref="y",
597
- x=x_val, # Use raw data value - Plotly handles log transformation
598
- y=row[y_col_to_use],
599
- sizex=logo_size_x,
600
- sizey=logo_size_y,
601
  xanchor="center",
602
  yanchor="middle",
603
  layer="above"
@@ -664,19 +688,19 @@ def _plot_scatter_plotly(
664
  fig.data = fig.data[:-1]
665
 
666
  # --- Section 8: Configure Layout ---
 
667
  xaxis_config = dict(
668
  title=x_axis_label,
669
  type="log",
670
- rangemode="tozero"
671
  )
672
 
673
-
674
  # Build layout configuration
675
  layout_config = dict(
676
  template="plotly_white",
677
  title=f"OpenHands Index {name} Leaderboard",
678
  xaxis=xaxis_config,
679
- yaxis=dict(title="Average (mean) score"),
680
  legend=dict(
681
  bgcolor='#FAF2E9',
682
  ),
 
570
  ))
571
 
572
  # Add company logo images for each data point
573
+ # Using domain coordinates (0-1 range) to work correctly with log scale x-axis
574
+ # Calculate axis ranges for coordinate conversion
575
+ min_cost = data_plot[x_col_to_use].min()
576
+ max_cost = data_plot[x_col_to_use].max()
577
+ min_score = data_plot[y_col_to_use].min()
578
+ max_score = data_plot[y_col_to_use].max()
579
+
580
+ # For log scale, we need log10 of the range bounds
581
+ # Add padding to the range
582
+ x_min_log = np.log10(min_cost * 0.5) if min_cost > 0 else -2
583
+ x_max_log = np.log10(max_cost * 1.3) if max_cost > 0 else 1
584
+ y_min = min_score - 5 if min_score > 5 else 0
585
+ y_max = max_score + 5
586
+
587
  for _, row in data_plot.iterrows():
588
  model_name = row.get('Language Model', '')
589
  company_info = get_company_from_model_name(model_name)
 
597
  logo_uri = f"data:image/svg+xml;base64,{encoded_logo}"
598
 
599
  x_val = row[x_col_to_use]
600
+ y_val = row[y_col_to_use]
601
+
602
+ # Convert to domain coordinates (0-1 range)
603
+ # For log scale x: domain_x = (log10(x) - x_min_log) / (x_max_log - x_min_log)
604
+ if x_val > 0:
605
+ log_x = np.log10(x_val)
606
+ domain_x = (log_x - x_min_log) / (x_max_log - x_min_log)
607
+ else:
608
+ domain_x = 0
609
 
610
+ # For linear y: domain_y = (y - y_min) / (y_max - y_min)
611
+ domain_y = (y_val - y_min) / (y_max - y_min) if (y_max - y_min) > 0 else 0.5
612
+
613
+ # Clamp to valid range
614
+ domain_x = max(0, min(1, domain_x))
615
+ domain_y = max(0, min(1, domain_y))
616
 
617
  layout_images.append(dict(
618
  source=logo_uri,
619
+ xref="x domain", # Use domain coordinates for log scale compatibility
620
+ yref="y domain",
621
+ x=domain_x,
622
+ y=domain_y,
623
+ sizex=0.04, # Size as fraction of plot width
624
+ sizey=0.06, # Size as fraction of plot height
625
  xanchor="center",
626
  yanchor="middle",
627
  layer="above"
 
688
  fig.data = fig.data[:-1]
689
 
690
  # --- Section 8: Configure Layout ---
691
+ # Use the same axis ranges as calculated for domain coordinates
692
  xaxis_config = dict(
693
  title=x_axis_label,
694
  type="log",
695
+ range=[x_min_log, x_max_log] # Match domain coordinate calculation
696
  )
697
 
 
698
  # Build layout configuration
699
  layout_config = dict(
700
  template="plotly_white",
701
  title=f"OpenHands Index {name} Leaderboard",
702
  xaxis=xaxis_config,
703
+ yaxis=dict(title="Average (mean) score", range=[y_min, y_max]), # Match domain calculation
704
  legend=dict(
705
  bgcolor='#FAF2E9',
706
  ),