How can I change legend bands and reflect those results on the mesh?

Member, Moderator, Employee Posts: 479
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭

How can I change legend bands and reflect those results on the mesh?

Tagged:

Comments

  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    edited January 2024

    You need to define scalar_bar_args argument for the plotter.add_field method. This will change only legend properties. To sync it with mesh, use same values for n_colors and n_labels as direct argument for plotter.add_field.

    1. import os
    2.  
    3. from ansys.dpf import core as dpf
    4. from ansys.dpf.core.plotter import DpfPlotter
    5.  
    6. out_path = r"\PATH\TO\RST"
    7. rst_path = os.path.join(out_path, "file.rst")
    8.  
    9. ds = dpf.DataSources(rst_path)
    10. model = dpf.Model(ds)
    11. mesh = model.metadata.meshed_region
    12.  
    13. nsn = ["B1", "B2"]
    14. for ns in nsn:
    15. mesh_scoping = dpf.operators.scoping.on_named_selection(named_selection_name=ns,
    16. data_sources=ds).outputs.mesh_scoping()
    17. mesh_region = dpf.operators.mesh.from_scoping(scoping=mesh_scoping, mesh=mesh).outputs.mesh()
    18. elastic_strain = dpf.operators.result.elastic_strain(data_sources=ds, requested_location="Nodal",
    19. mesh_scoping=mesh_scoping)
    20. es_f = elastic_strain.outputs.fields_container()[0]
    21.  
    22. plotter = DpfPlotter()
    23. sargs = dict(title="Legend", fmt="%.2e", title_font_size=30, label_font_size=20, n_labels=3, n_colors=2)
    24. plotter.add_field(es_f, meshed_region=mesh_region,
    25. label_text_size=15,
    26. label_point_size=5,
    27. scalar_bar_args=sargs,
    28. n_colors=2,
    29. n_labels=3)
    30.  
    31. plotter.show_figure()

Welcome!

It looks like you're new here. Sign in or register to get started.