File size: 1,529 Bytes
3caa485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pandas as pd
import plotly.graph_objs as go


def visualize(cluster_data):

    # Create a DataFrame with counts of each category
    category_counts = {}
    for paper in cluster_data:
        categories = paper["categories"]
        for category in categories:
            if category in category_counts:
                category_counts[category] += 1
            else:
                category_counts[category] = 1

    category_df = pd.DataFrame(
        {
            "Category": list(category_counts.keys()),
            "Count": list(category_counts.values()),
        }
    )

    # Sort the DataFrame by count in descending order
    category_df = category_df.sort_values(by="Count", ascending=False)

    # Create hover text containing the count and titles of all papers for each category
    hover_text = []
    for category in category_df["Category"]:
        titles = []
        for paper in cluster_data:
            if category in paper["categories"]:
                titles.append(f'<a href="https://plot.ly/">{paper["paper"]}</a>')
        hover_text.append(f'<br>Papers:<br>{"<br>".join(titles)}')

    # Create Plotly Bar chart
    fig = go.Figure(
        data=[
            go.Bar(
                x=category_df["Category"],
                y=category_df["Count"],
                hovertext=hover_text,
                marker=dict(color="brown"),
            )
        ]
    )

    # Update layout
    fig.update_layout(title="Categories", xaxis_title="Category", yaxis_title="Count")

    return fig