-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_htmls.py
More file actions
82 lines (70 loc) · 2.19 KB
/
gen_htmls.py
File metadata and controls
82 lines (70 loc) · 2.19 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import sys
# Load data
df = pd.read_csv(sys.argv[1])
# Clean up
df = df.drop(columns=['Unnamed: 5'])
# Sort
# df = df.sort_values(by='citations', ascending=False)
# Shorten titles for axis
df['Title_Short'] = df['Title'].apply(lambda x: str(x)[:40] + '...' if len(str(x)) > 40 else str(x))
# Create figure
fig = make_subplots(specs=[[{"secondary_y": True}]])
# Bar trace for Citations
fig.add_trace(
go.Bar(
x=df['Title_Short'],
y=df['citations'],
name="Citations",
marker_color='rgb(55, 83, 109)',
customdata=df[['Title', '% of total', 'Cummulative']],
hovertemplate="<b>%{customdata[0]}</b><br>" +
"Citations: %{y}<br>" +
"% of Total: %{customdata[1]:.2%}<br>" +
"Cumulative: %{customdata[2]:.2%}<extra></extra>"
),
secondary_y=False,
)
# Line trace for Cumulative %
fig.add_trace(
go.Scatter(
x=df['Title_Short'],
y=df['Cummulative'],
name="Cumulative %",
marker_color='rgb(26, 118, 255)',
mode='lines+markers',
customdata=df[['Title']],
hovertemplate="<b>%{customdata[0]}</b><br>Cumulative: %{y:.2%}<extra></extra>"
),
secondary_y=True,
)
# Layout
fig.update_layout(
title_text="Citation Counts and Cumulative Distribution (" + sys.argv[2] + ")",
xaxis_title="Paper Title",
hovermode="x unified",
legend=dict(x=0.7, y=0.9),
margin=dict(b=150)
)
fig.update_xaxes(tickangle=45)
fig.update_yaxes(title_text="<b>Citation Count</b>", secondary_y=False)
fig.update_yaxes(title_text="<b>Cumulative %</b>", secondary_y=True, tickformat='.0%')
# Update the primary y-axis (Citations) to use a log scale
fig.update_yaxes(
title_text="<b>Citation Count</b>",
secondary_y=False,
type="log" # <--- Add this line
)
# The secondary y-axis (Cumulative %) remains linear
fig.update_yaxes(
title_text="<b>Cumulative %</b>",
secondary_y=True,
tickformat='.0%'
)
# Save
# output_file = 'citation_visualization.html'
output_file = sys.argv[3]
fig.write_html(output_file)
print(f"File saved: {output_file}")