Fixed plot not loading issue (ensured correct file save path)
Browse files
app.py
CHANGED
|
@@ -29,11 +29,17 @@ def plot_function(func_str, x_min, x_max, resolution, color, linestyle, grid):
|
|
| 29 |
if grid:
|
| 30 |
plt.grid()
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
plt.close()
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error: {e}", None
|
|
|
|
| 29 |
if grid:
|
| 30 |
plt.grid()
|
| 31 |
|
| 32 |
+
# Save the plot correctly and return an absolute path
|
| 33 |
+
plot_filename = "high_res_plot.png"
|
| 34 |
+
abs_path = os.path.abspath(plot_filename) # Convert to absolute path
|
| 35 |
+
plt.savefig(abs_path, dpi=300)
|
| 36 |
plt.close()
|
| 37 |
|
| 38 |
+
# Ensure the file exists before returning
|
| 39 |
+
if os.path.exists(abs_path):
|
| 40 |
+
return abs_path, abs_path
|
| 41 |
+
else:
|
| 42 |
+
return "Error: Plot file was not created", None
|
| 43 |
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error: {e}", None
|