Skip to content

Commit a3b45d2

Browse files
roosregreschd
andauthored
Improve Examples (minor changes) (#564)
* Improve examples section. --------- Co-authored-by: Dominik Gresch <[email protected]>
1 parent 627a3b1 commit a3b45d2

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

examples/002_sampling_point_example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
# DPF server, and retrieving the example files.
5252
#
5353
# Load Ansys libraries.
54-
5554
from ansys.dpf.composites.composite_model import CompositeModel
5655
from ansys.dpf.composites.constants import Spot
5756
from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files
@@ -105,17 +104,17 @@
105104
)
106105
sampling_point_plot.figure.set_figheight(8)
107106
sampling_point_plot.figure.set_figwidth(12)
107+
sampling_point_plot.figure.show()
108108

109109
# %%
110110
# Plot polar properties.
111111
sampling_point_plot = sampling_point.get_polar_plot(["E1", "G12"])
112-
112+
sampling_point_plot.figure.show()
113113
# %%
114114
# Generate custom plots. You can customize existing plots or build
115115
# them from scratch using a package like Matplot or Plotly. This code
116116
# uses Matplotlib to generate a custom plot of results ``s13`` and ``s23``.
117117
#
118-
119118
import matplotlib.pyplot as plt
120119

121120
fig, ax1 = plt.subplots()
@@ -133,6 +132,7 @@
133132
plt.rcParams["hatch.linewidth"] = 0.2
134133
plt.rcParams["hatch.color"] = "silver"
135134
sampling_point.add_ply_sequence_to_plot(ax1, core_scale_factor)
135+
fig.show()
136136

137137
# %%
138138
# This code uses Matplotlib to generate a custom plot of results ``e12`` and ``e2``.
@@ -152,11 +152,13 @@
152152
ax1.set_yticks([])
153153
ax1.legend()
154154
ax1.set_title("e12 and e2")
155+
fig.show()
155156

156157
# %%
157158
# This code plots the lay-up only.
158159
fig2, layup_axes = plt.subplots()
159160
sampling_point.add_ply_sequence_to_plot(layup_axes)
161+
fig2.show()
160162

161163
# %%
162164
# Sample another element
@@ -172,3 +174,4 @@
172174
)
173175
sampling_point_plot.figure.set_figheight(8)
174176
sampling_point_plot.figure.set_figwidth(12)
177+
sampling_point_plot.figure.show()

examples/003_short_fiber_example.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@
9191

9292
field_variables = field_variable_provider.outputs.fields_container.get_data()
9393

94-
a11 = field_variables[0]
95-
a11.plot()
96-
9794
# %%
98-
99-
a22 = field_variables[1]
100-
a22.plot()
95+
# Note that the order of the results can differ from the one shown here.
96+
for index in range(len(field_variables)):
97+
field_variable = field_variables[index]
98+
print(f"Field variable {field_variable.name}")
99+
field_variable.plot()
101100

102101
# %%
103102
# Configure and evaluate

examples/README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@
55
Examples
66
========
77
These examples demonstrate the behavior and usage of PyDPF - Composites.
8+
Some additional modules are required to run the examples which can be
9+
installed with the following command:
10+
11+
.. code::
12+
13+
pip install ansys-dpf-composites[examples]
14+
15+
It is recommended to run the examples in a Jupyter notebook or an IPython console.
16+
Copy / pasting to a standard Python interactive shell can lead to formatting issues (e.g. IndentationError).
17+
This issue is resolved with Python 3.13 and later.

0 commit comments

Comments
 (0)