Jupyter notebook plotting#

This example demonstrates the Jupyter notebook support for deck.plot(). The plotting system automatically detects Jupyter environments and adjusts the PyVista backend accordingly.

When running in a Jupyter notebook, PyDyna automatically uses the ‘static’ backend for screenshots, or you can explicitly choose ‘server’ for interactive widgets. Outside Jupyter, it uses the standard PyVista behavior.

See GitHub issue #601 for details.

Perform required imports#

Import required packages.

import pandas as pd

from ansys.dyna.core import Deck, keywords as kwd

Create a simple deck#

Create a deck with 8 nodes forming a hex element.

deck = Deck()

# Create 8 nodes for a hex element
node_kwd = kwd.Node()
nodes_data = pd.DataFrame(
    {
        "nid": [1, 2, 3, 4, 5, 6, 7, 8],
        "x": [0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0],
        "y": [0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0],
        "z": [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0],
    }
)
node_kwd.nodes = nodes_data
deck.append(node_kwd)

# Create a solid element
solid_kwd = kwd.ElementSolid()
elements_data = pd.DataFrame(
    {"eid": [1], "pid": [1], "n1": [1], "n2": [2], "n3": [3], "n4": [4], "n5": [5], "n6": [6], "n7": [7], "n8": [8]}
)
solid_kwd.elements = elements_data
deck.append(solid_kwd)

# Add a section
section_kwd = kwd.SectionSolid(secid=1)
section_kwd.elform = 1
deck.append(section_kwd)

print(f"Deck created with {len(deck)} keywords")
Deck created with 3 keywords

Plot with auto-detection#

In Jupyter notebooks, this automatically uses the ‘static’ backend. Outside Jupyter, it uses the default PyVista behavior.

# deck.plot()

Plot with explicit backend#

You can explicitly specify the backend: - ‘static’: screenshot (fast, works everywhere) - ‘server’: interactive widget (requires jupyter-server-proxy) - ‘trame’: trame-based viewer (experimental) - None: disable Jupyter handling, use standard PyVista

# deck.plot(jupyter_backend='static')

Plot with custom styling#

All standard PyVista plot options work with Jupyter:

# deck.plot(jupyter_backend='static', color='lightblue', show_edges=True)

Total running time of the script: (0 minutes 0.016 seconds)

Gallery generated by Sphinx-Gallery