Untitled

 avatar
unknown
plain_text
14 days ago
1.4 kB
5
Indexable
import pandas as pd
import matplotlib.pyplot as plt
import logging

def generate_visualizations(remake_df, feature_insights):
    try:
        # Pie Chart: Remake/Remaster Distribution
        classification_counts = remake_df['classification'].value_counts()
        total = classification_counts.sum()
        classification_counts.plot(
            kind='pie',
            autopct=lambda p: f'{p:.1f}%\n({int(p * total / 100)})',
            title='Remake/Remaster Distribution',
            figsize=(8, 8)
        )
        plt.ylabel('')  # Hide y-label for better aesthetics
        plt.savefig('classification_distribution.png')
        plt.clf()

        # Bar Chart: Key Features in Remakes (From LLM Insights)
        features = feature_insights['features']
        feature_names = list(features.keys())
        feature_counts = list(features.values())
        plt.figure(figsize=(12, 10))  # Increased figure size for better readability
        plt.barh(feature_names, feature_counts, color="skyblue")
        plt.xlabel('Frequency')
        plt.ylabel('Features')
        plt.title('Key Features in Remakes (LLM Insights)')
        plt.gca().yaxis.set_tick_params(pad=10)  # Add more space between the feature names
        plt.tight_layout()
        plt.savefig('feature_distribution.png')
        plt.clf()

    except Exception as e:
        logging.error(f"Error in generate_visualizations: {e}")
Leave a Comment