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: object

Interactive stress transformation viewer with matplotlib.

Combines stress analysis, Mohr’s circle, and animation in one viewer.

Parameters:
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

save(filename='stress_viewer.png', dpi=150)[source]

Save current view to file.

Parameters:
Return type:

None

Animations

class mechlab.visual.StressAnimation(sx, sy, txy)[source]

Bases: object

Export 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")
Parameters:
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.

Parameters:
  • filename (str) – Output filename

  • fps (int) – Frames per second

  • frames (int) – Total number of frames

Return type:

None

save_gif(filename='stress_animation.gif', fps=20, frames=100)[source]

Save animation as GIF.

Parameters:
  • filename (str) – Output filename

  • fps (int) – Frames per second

  • frames (int) – Total number of frames

Return type:

None

Beam Plots

class mechlab.visual.BeamPlot(beam)[source]

Bases: object

Visualization 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.

Parameters:

figsize (tuple[float, float]) – Figure size (width, height) in inches

Return type:

None

save(filename='beam_diagrams.png', dpi=150)[source]

Save diagrams to file.

Parameters:
  • filename (str) – Output filename

  • dpi (int) – Image resolution

Return type:

None

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:
  • initial_sx (float) – Initial normal stress in x-direction (MPa)

  • initial_sy (float) – Initial normal stress in y-direction (MPa)

  • initial_txy (float) – Initial shear stress (MPa)

Raises:

RuntimeError – If ipywidgets is not available

Return type:

None

Example

>>> from mechlab.visual import stress_widget
>>> stress_widget()  # In Jupyter notebook