bluenevus commited on
Commit
1b2886c
·
verified ·
1 Parent(s): ac4bba9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -32,24 +32,29 @@ def process_file(api_key, file, instructions):
32
  # Generate visualizations
33
  images = []
34
  for plot in plots[:3]: # Ensure max 3 plots
35
- fig = plt.figure()
36
  title, plot_type, x, y = plot
37
 
38
  if plot_type == 'bar':
39
- df.plot.bar(x=x, y=y, ax=plt.gca())
40
  elif plot_type == 'line':
41
- df.plot.line(x=x, y=y, ax=plt.gca())
42
  elif plot_type == 'scatter':
43
- df.plot.scatter(x=x, y=y, ax=plt.gca())
44
  elif plot_type == 'hist':
45
- df[y].hist(ax=plt.gca())
 
 
 
 
 
46
 
47
- plt.title(title)
48
  buf = io.BytesIO()
49
- fig.savefig(buf, format='png', bbox_inches='tight')
50
  buf.seek(0)
51
- images.append(Image.open(buf))
52
- plt.close()
 
53
 
54
  return images if len(images) == 3 else images + [Image.new('RGB', (800, 600), (255,255,255))]*(3-len(images))
55
 
 
32
  # Generate visualizations
33
  images = []
34
  for plot in plots[:3]: # Ensure max 3 plots
35
+ fig, ax = plt.subplots(figsize=(10, 6))
36
  title, plot_type, x, y = plot
37
 
38
  if plot_type == 'bar':
39
+ df.plot(kind='bar', x=x, y=y, ax=ax)
40
  elif plot_type == 'line':
41
+ df.plot(kind='line', x=x, y=y, ax=ax)
42
  elif plot_type == 'scatter':
43
+ df.plot(kind='scatter', x=x, y=y, ax=ax)
44
  elif plot_type == 'hist':
45
+ df[y].hist(ax=ax)
46
+
47
+ ax.set_title(title)
48
+ ax.set_xlabel(x)
49
+ ax.set_ylabel(y)
50
+ plt.tight_layout()
51
 
 
52
  buf = io.BytesIO()
53
+ plt.savefig(buf, format='png')
54
  buf.seek(0)
55
+ img = Image.open(buf)
56
+ images.append(img)
57
+ plt.close(fig)
58
 
59
  return images if len(images) == 3 else images + [Image.new('RGB', (800, 600), (255,255,255))]*(3-len(images))
60