Visualization¶
Interactive plots, animations, and widgets.
Visualization tools for engineering analysis.
- Provides:
StressViewer: Interactive stress analysis with Mohr’s circle
BeamPlot: Shear force and bending moment diagrams
StressAnimation: Export stress transformation animations
stress_widget: Jupyter notebook widget for stress analysis
Requires: matplotlib, numpy Optional: ipywidgets (for Jupyter widgets)
Interactive Viewer¶
- class mechlab.visual.StressViewer(sx=100, sy=50, txy=25, unit='MPa')[source]
Bases:
objectInteractive stress transformation viewer with matplotlib.
Combines stress analysis, Mohr’s circle, and animation in one viewer.
- sx
Normal stress in x-direction
- sy
Normal stress in y-direction
- txy
Shear stress
- unit
Stress unit (default: MPa)
Example
>>> from mechlab.visual import StressViewer >>> viewer = StressViewer(100, 50, 25) >>> viewer.show()
- show()[source]
Display the interactive viewer.
- Return type:
None
Animations¶
- class mechlab.visual.StressAnimation(sx, sy, txy)[source]
Bases:
objectExport stress transformation animation to video or GIF.
Creates an animation showing how stress components change as the coordinate system rotates through 360 degrees.
Example
>>> from mechlab.visual import StressAnimation >>> anim = StressAnimation(100, 50, 25) >>> anim.save_gif("stress.gif")
- preview()[source]
Preview animation in matplotlib window.
- Return type:
None
- save_mp4(filename='stress_animation.mp4', fps=30, frames=200)[source]
Save animation as MP4 video.
Beam Plots¶
- class mechlab.visual.BeamPlot(beam)[source]
Bases:
objectVisualization for beam analysis.
Creates shear force and bending moment diagrams.
Example
>>> from mechlab.mechanics.beam import SimplySupportedBeam >>> beam = SimplySupportedBeam(5, 1000, 200e9, 1e-4) >>> BeamPlot(beam).show()
- Parameters:
beam (SimplySupportedBeam)
- show(figsize=(10, 6))[source]
Display shear and moment diagrams.
Jupyter Widgets¶
- mechlab.visual.stress_widget(initial_sx=100.0, initial_sy=50.0, initial_txy=25.0)[source]
Display interactive stress widget in Jupyter notebook.
Creates sliders for σx, σy, and τxy with real-time calculation of principal stresses, maximum shear, and von Mises stress.
- Parameters:
- Raises:
RuntimeError – If ipywidgets is not available
- Return type:
None
Example
>>> from mechlab.visual import stress_widget >>> stress_widget() # In Jupyter notebook