karthikmn commited on
Commit
1cf39f1
·
verified ·
1 Parent(s): 8203723

Create visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +19 -0
visualization.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pyvista as pv
2
+ import matplotlib.pyplot as plt
3
+
4
+ def visualize_results(simulator, length, width, thickness, stress, deformation):
5
+ # 2D Bar Plot
6
+ fig, ax = plt.subplots()
7
+ ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
8
+ ax.set_title(f"Results ({simulator})")
9
+ plt.savefig("results_2d.png")
10
+ plt.close(fig)
11
+
12
+ # 3D Visualization
13
+ mesh = pv.Box(bounds=(0, length, 0, width, 0, thickness))
14
+ mesh["Stress"] = stress
15
+ plotter = pv.Plotter(off_screen=True)
16
+ plotter.add_mesh(mesh, scalars="Stress", cmap="coolwarm")
17
+ plotter.show(screenshot="results_3d.png")
18
+
19
+ return "results_2d.png", "results_3d.png"