# visualization/plot_generator.py """Main plotting functionality for similarity analysis""" import pandas as pd import plotly.graph_objects as go from plotly.subplots import make_subplots from typing import Tuple, Optional, Union import sys import os # Add parent directory to path for imports sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) class PlotGenerator: """Handles creation of plotly visualizations""" def __init__(self, data_loader): self.data_loader = data_loader def compute_category_correlation_method2(self, category_key: str, target_series: pd.Series) -> float: """ Compute correlation using Method 2: Correlate each model, then average correlations. This matches the bar chart methodology. Args: category_key: Category name like 'vision', 'captions_neural', etc. target_series: The series to correlate with (e.g., brain measure or human judgement) Returns: Average correlation across all models in the category """ import numpy as np # Get models in this category models = [model[0] for model in self.data_loader.model_categories[category_key]] if not models: return 0.0 # Filter to available models data = self.data_loader.data available_models = [m for m in models if m in data.columns] if not available_models: return 0.0 # Compute correlation for each model correlations = [] for model in available_models: corr = data[model].corr(target_series) if not np.isnan(corr): correlations.append(corr) # Return average correlation if correlations: return np.mean(correlations) else: return 0.0 @staticmethod def add_image_hover_to_html(html_str: str) -> str: """Add custom JavaScript to enable image preview on hover for image pairs""" custom_code = """