YchKhan commited on
Commit
d3336a3
1 Parent(s): 0b2c90c

Update chart_generation.py

Browse files
Files changed (1) hide show
  1. chart_generation.py +5 -3
chart_generation.py CHANGED
@@ -18,7 +18,7 @@ def create_bar_plot(file, x_values, y_values):
18
  plt.ylabel('Count')
19
  else:
20
  count_df = df.groupby(['Simple_Source', y_values]).size().unstack(fill_value=0)
21
- fig, ax = plt.subplots(figsize=(10, 7))
22
 
23
  count_df.plot(kind='bar', stacked=True, ax=ax)
24
 
@@ -29,11 +29,13 @@ def create_bar_plot(file, x_values, y_values):
29
  plt.ylabel('Number of Contributions')
30
  plt.title(f'Number of Contributions by {y_values} and {x_values}')
31
 
32
- for i, bar in enumerate(fig.patches):
33
  h = bar.get_height()
34
  w = bar.get_width()
35
  x = bar.get_x()
36
  y = bar.get_y()
37
  if h > 0:
38
- plt.text(x + w/2, y + h/2, int(h), ha='center', va='center')
 
 
39
  return fig
 
18
  plt.ylabel('Count')
19
  else:
20
  count_df = df.groupby(['Simple_Source', y_values]).size().unstack(fill_value=0)
21
+ fig, ax = plt.subplots(figsize=(12, 7))
22
 
23
  count_df.plot(kind='bar', stacked=True, ax=ax)
24
 
 
29
  plt.ylabel('Number of Contributions')
30
  plt.title(f'Number of Contributions by {y_values} and {x_values}')
31
 
32
+ for i, bar in enumerate(ax.patches):
33
  h = bar.get_height()
34
  w = bar.get_width()
35
  x = bar.get_x()
36
  y = bar.get_y()
37
  if h > 0:
38
+ ax.text(x + w/2, y + h/2, int(h), ha='center', va='center')
39
+
40
+ plt.tight_layout()
41
  return fig