karthikmn commited on
Commit
ad4cdd1
·
verified ·
1 Parent(s): 1b42a61

Create visualization.py

Browse files
Files changed (1) hide show
  1. modules/visualization.py +25 -0
modules/visualization.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import io
3
+ from PIL import Image
4
+
5
+ def plot_simulation_results(data):
6
+ try:
7
+ stress = data.get("stress", [])
8
+ strain = data.get("strain", [])
9
+
10
+ plt.figure(figsize=(8, 6))
11
+ plt.plot(stress, strain, marker="o", label="Stress-Strain Curve")
12
+ plt.title("Simulation Results")
13
+ plt.xlabel("Stress (MPa)")
14
+ plt.ylabel("Strain")
15
+ plt.legend()
16
+ plt.grid(True)
17
+
18
+ buf = io.BytesIO()
19
+ plt.savefig(buf, format="png")
20
+ buf.seek(0)
21
+ plt.close()
22
+
23
+ return Image.open(buf)
24
+ except Exception as e:
25
+ return f"Error in visualization: {str(e)}"