File size: 688 Bytes
ad4cdd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import matplotlib.pyplot as plt
import io
from PIL import Image

def plot_simulation_results(data):
    try:
        stress = data.get("stress", [])
        strain = data.get("strain", [])
        
        plt.figure(figsize=(8, 6))
        plt.plot(stress, strain, marker="o", label="Stress-Strain Curve")
        plt.title("Simulation Results")
        plt.xlabel("Stress (MPa)")
        plt.ylabel("Strain")
        plt.legend()
        plt.grid(True)
        
        buf = io.BytesIO()
        plt.savefig(buf, format="png")
        buf.seek(0)
        plt.close()
        
        return Image.open(buf)
    except Exception as e:
        return f"Error in visualization: {str(e)}"