Weyaxi commited on
Commit
9eb9b68
·
verified ·
1 Parent(s): 4599eda

Update plot_graph.py

Browse files
Files changed (1) hide show
  1. plot_graph.py +9 -45
plot_graph.py CHANGED
@@ -8,17 +8,12 @@ from scipy.ndimage import gaussian_filter1d
8
 
9
  snapshot_download("Weyaxi/followers-leaderboard", local_dir="followers-leaderboard", repo_type="dataset", max_workers=32)
10
 
11
-
12
  global_dataset_dfs = {}
13
- COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd',
14
- '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']
15
-
16
 
17
- def plot_follower_comparison(author_names, dataset_path="followers-leaderboard", smooth_sigma=1.5):
18
  if isinstance(author_names, str):
19
  author_names = [author_names]
20
 
21
- print(author_names)
22
  # Load or retrieve cached DataFrames
23
  if dataset_path not in global_dataset_dfs:
24
  dfs = {}
@@ -37,10 +32,9 @@ def plot_follower_comparison(author_names, dataset_path="followers-leaderboard",
37
  else:
38
  dfs = global_dataset_dfs[dataset_path]
39
 
40
- fig, ax = plt.subplots(figsize=(14, 8)) # Create a new figure
41
- valid_authors = []
42
-
43
- for idx, author in enumerate(author_names):
44
  date_count = {}
45
  for date, df in dfs.items():
46
  if author in df['Author'].values:
@@ -55,40 +49,10 @@ def plot_follower_comparison(author_names, dataset_path="followers-leaderboard",
55
  if smooth_sigma > 0 and len(counts) > 1:
56
  counts = gaussian_filter1d(counts, sigma=smooth_sigma)
57
 
58
- # Plot styling
59
- color = COLORS[idx % len(COLORS)]
60
- style = ['-', '--', '-.', ':'][idx % 4]
61
- marker = ['o', 's', 'D', '^', 'v'][idx % 5] if idx < 5 else None
62
-
63
- ax.plot(dates, counts,
64
- linestyle=style,
65
- color=color,
66
- marker=marker,
67
- markersize=7 if marker else 0,
68
- linewidth=2.5,
69
- markevery=0.1,
70
- alpha=0.9,
71
- label=author)
72
- valid_authors.append(author)
73
-
74
- if not valid_authors:
75
- print("No valid data found for any authors.")
76
- return None
77
-
78
- # Plot configuration
79
- ax.set_title(f'Follower Trend Comparison ({", ".join(valid_authors)})', pad=20)
80
- ax.set_xlabel('Date', labelpad=15)
81
- ax.set_ylabel('Followers', labelpad=15)
82
- ax.set_ylim(bottom=0)
83
- ax.grid(True, alpha=0.25)
84
-
85
- # Date formatting
86
- ax.xaxis.set_major_formatter(plt.matplotlib.dates.DateFormatter('%d-%m-%Y'))
87
- plt.xticks(rotation=45, ha='right')
88
 
89
- # Legend and layout
90
- ax.legend(loc='upper left', bbox_to_anchor=(1, 1), framealpha=0.9)
91
- plt.tight_layout()
92
 
93
- return fig # Return the figure instead of plt
94
-
 
8
 
9
  snapshot_download("Weyaxi/followers-leaderboard", local_dir="followers-leaderboard", repo_type="dataset", max_workers=32)
10
 
 
11
  global_dataset_dfs = {}
 
 
 
12
 
13
+ def gr_plot_follower_comparison(author_names, dataset_path="followers-leaderboard", smooth_sigma=1.5):
14
  if isinstance(author_names, str):
15
  author_names = [author_names]
16
 
 
17
  # Load or retrieve cached DataFrames
18
  if dataset_path not in global_dataset_dfs:
19
  dfs = {}
 
32
  else:
33
  dfs = global_dataset_dfs[dataset_path]
34
 
35
+ data = []
36
+
37
+ for author in author_names:
 
38
  date_count = {}
39
  for date, df in dfs.items():
40
  if author in df['Author'].values:
 
49
  if smooth_sigma > 0 and len(counts) > 1:
50
  counts = gaussian_filter1d(counts, sigma=smooth_sigma)
51
 
52
+ for d, c in zip(dates, counts):
53
+ data.append({"x": d, "y": c, "author": author})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
+ if not data:
56
+ return pd.DataFrame(columns=["x", "y", "author"])
 
57
 
58
+ return pd.DataFrame(data)