Skip to content

Commit

Permalink
Update gif embedding (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
dipinknair authored Jan 16, 2024
1 parent 6ac9ec6 commit 53cb13f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
Binary file removed doc/source/_static/basic/Valve.gif
Binary file not shown.
2 changes: 2 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"image_scrapers": ("pyvista", "matplotlib"),
"ignore_pattern": "flycheck*",
"thumbnail_size": (350, 350),
# embed gif in gallery
"matplotlib_animations": True,
}

# Intersphinx mapping
Expand Down
12 changes: 7 additions & 5 deletions examples/basic/topology_optimization_cantilever_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@


def display_image(image_name):
path = os.path.join(os.path.join(cwd, image_name))
image = mpimg.imread(path)
plt.figure(figsize=(15, 15))
plt.axis("off")
plt.imshow(image)
plt.figure(figsize=(16, 9))
plt.imshow(mpimg.imread(os.path.join(cwd, image_name)))
plt.xticks([])
plt.yticks([])
plt.show()


Expand Down Expand Up @@ -199,6 +198,9 @@ def display_image(image_name):
print("Final Mass: ", TOPO_DENS.FinalMass.Value)
print("Percent Mass of Original: ", TOPO_DENS.PercentMassOfOriginal)

# %%
# Cleanup
# ~~~~~~~
# Save project
app.save(os.path.join(cwd, "cantilever_beam_topology_optimization.mechdat"))
app.new()
Expand Down
32 changes: 25 additions & 7 deletions examples/basic/valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"""
import os

from PIL import Image
import ansys.mechanical.core as mech
from ansys.mechanical.core.examples import delete_downloads, download_file
from matplotlib import image as mpimg
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation

# Embed Mechanical and set global variables
app = mech.App(version=232)
Expand All @@ -24,11 +26,10 @@


def display_image(image_name):
path = os.path.join(os.path.join(cwd, image_name))
image = mpimg.imread(path)
plt.figure(figsize=(15, 15))
plt.axis("off")
plt.imshow(image)
plt.figure(figsize=(16, 9))
plt.imshow(mpimg.imread(os.path.join(cwd, image_name)))
plt.xticks([])
plt.yticks([])
plt.show()


Expand Down Expand Up @@ -154,12 +155,29 @@ def display_image(image_name):
stress.ExportAnimation(
os.path.join(cwd, "Valve.gif"), animation_export_format, settings_720p
)
gif = Image.open(os.path.join(cwd, "Valve.gif"))
fig, ax = plt.subplots(figsize=(16, 9))
ax.axis("off")
img = ax.imshow(gif.convert("RGBA"))

# %%
# .. image:: /_static/basic/Valve.gif

def update(frame):
gif.seek(frame)
img.set_array(gif.convert("RGBA"))
return [img]


ani = FuncAnimation(
fig, update, frames=range(gif.n_frames), interval=100, repeat=True, blit=True
)
plt.show()


# %%
# Cleanup
# ~~~~~~~
# Save project

app.save(os.path.join(cwd, "Valve.mechdat"))
app.new()

Expand Down
9 changes: 4 additions & 5 deletions examples/technology_showcase/Rotor_Blade_Inverse_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@


def display_image(image_name):
path = os.path.join(os.path.join(cwd, image_name))
image = mpimg.imread(path)
plt.figure(figsize=(15, 15))
plt.axis("off")
plt.imshow(image)
plt.figure(figsize=(16, 9))
plt.imshow(mpimg.imread(os.path.join(cwd, image_name)))
plt.xticks([])
plt.yticks([])
plt.show()


Expand Down

0 comments on commit 53cb13f

Please sign in to comment.