How can one save a plot of a pydpf result when using pypdf in standalone (IDE) mode?

M
M Member, Employee Posts: 199
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

This is the standard question from customers who are partaking in a pyanys discussion, how can they plot results to file.

They would like plots/images of the results that are created and pop up when using pyansys tools. If they were matplotlib plots it would be possible to write them to file.

How to do similar with the pydpf results.

Tagged:

Answers

  • M
    M Member, Employee Posts: 199
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    from ansys.dpf import core as dpf
    from ansys.dpf.core import examples
    from ansys.dpf.core.plotter import DpfPlotter
    
    # Here we create a Model and request its mesh and a displacement result
    model = dpf.Model(examples.msup_transient)
    mesh = model.metadata.meshed_region
    disp = model.results.displacement().outputs.fields_container()[0]
    
    # Then we plot and save the screenshot
    pl = DpfPlotter(notebook=False) # set notebook to false to disable showing in the current window
    pl.add_field(disp, mesh)
    pl.show_figure(screenshot='D:\my_screenshot.png') # set screenshot file_path