Skip to content

Be able to save system diagram to file instead of the displaying it in the ipnyb notebook #455

Description

@Sridhar701Pitt

It is helpful to save the output of the Render Diagram function to a file instead of the ipnyb output block since the image is too big to comfortably view in the otuput window (pan, zoom, etc.. is not very user friendly). Saving to file (.svg) makes it easier so the user can view in any viewer.

from pydrake.systems.framework import System
import pydot

def SaveDiagramToFile(system: System, file_path: str, max_depth: int | None = None):
    """Save the GraphViz diagram of the given system to a file.

    Args:
        system (System): The Drake system (or diagram) to render.
        file_path (str): The file path where the diagram will be saved.
        max_depth (int, optional): Sets a limit to the depth of nested diagrams
            to visualize. Use zero to render a diagram as a single system
            block. Defaults to 1.
    """
    graph = pydot.graph_from_dot_data(system.GetGraphvizString(max_depth=max_depth))[0]
    graph.write_svg(file_path)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions