Skip to content

Commit 9b0672e

Browse files
germa89pyansys-ci-botRevathyvenugopal162
authored
docs: adding plottly support to gallery examples (#2346)
* Changing configuration * Using plotly in gallery example * chore: adding changelog file 2346.documentation.md [dependabot-skip] * test: using jorge's suggestion * chore: adding changelog file 2346.documentation.md [dependabot-skip] * build: install ansys-sphinx-theme from specific branch in documentation workflow * test: temporory disable linkcode * test: plotly version * fix: revert changes * fix: add js in conf.py file * Update .github/workflows/doc-build.yml * Update .github/workflows/doc-build.yml * Update .github/workflows/doc-build.yml * fix: update the theme version * Update .github/workflows/doc-build.yml * Update pyproject.toml * Update pyproject.toml * Update .github/workflows/doc-build.yml --------- Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Revathyvenugopal162 <[email protected]> Co-authored-by: Revathy Venugopal <[email protected]>
1 parent 6a922e0 commit 9b0672e

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

doc/changelog.d/2346.documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs: adding plottly support to gallery examples

doc/source/conf.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
import ansys.tools.visualization_interface as viz_interface
1010
from ansys_sphinx_theme import ansys_favicon, get_version_match
1111
import numpy as np
12+
import plotly.io as pio
13+
from plotly.io._sg_scraper import plotly_sg_scraper
1214
import pyvista
1315
from sphinx.application import Sphinx
1416
from sphinx.util import logging
1517
from sphinx_gallery.sorting import FileNameSortKey
1618

19+
pio.renderers.default = "sphinx_gallery"
20+
1721
from ansys.mapdl import core as pymapdl
1822
from ansys.mapdl.core import __version__
1923

@@ -276,7 +280,11 @@
276280
"backreferences_dir": None,
277281
# Modules for which function level galleries are created. In
278282
"doc_module": "ansys-mapdl-core",
279-
"image_scrapers": ("pyvista", "matplotlib"),
283+
"image_scrapers": (
284+
"pyvista",
285+
"matplotlib",
286+
plotly_sg_scraper,
287+
),
280288
"ignore_pattern": "flycheck*",
281289
"thumbnail_size": (350, 350),
282290
"remove_config_comments": True,
@@ -355,6 +363,8 @@
355363
html_show_sourcelink = False
356364

357365

366+
html_js_files = ["https://cdn.plot.ly/plotly-3.0.1.min.js"]
367+
358368
# -- Options for HTMLHelp output ---------------------------------------------
359369

360370
# Output file base name for HTML help builder.

examples/00-mapdl-examples/2d_plate_with_a_hole.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"""
3535
# sphinx_gallery_thumbnail_number = 3
3636

37-
import matplotlib.pyplot as plt
3837
import numpy as np
38+
import plotly.graph_objects as go
3939

4040
from ansys.mapdl.core import launch_mapdl
4141

@@ -396,12 +396,24 @@ def compute_stress_con(ratio):
396396
# where ratio is (d/h)
397397
k_t_anl = 3 - 3.14 * ratios + 3.667 * ratios**2 - 1.527 * ratios**3
398398

399-
plt.plot(ratios, k_t_anl, label=r"$K_t$ Analytical")
400-
plt.plot(ratios, k_t_exp, label=r"$K_t$ ANSYS")
401-
plt.legend()
402-
plt.xlabel("Ratio of Hole Diameter to Width of Plate")
403-
plt.ylabel("Stress Concentration")
404-
plt.show()
399+
400+
# Create traces
401+
fig = go.Figure()
402+
fig.add_trace(
403+
go.Scatter(x=ratios, y=k_t_anl, mode="lines", name=r"$K_t \text{ Analytical}$")
404+
)
405+
fig.add_trace(
406+
go.Scatter(x=ratios, y=k_t_exp, mode="lines+markers", name=r"$K_t \text{ ANSYS}$")
407+
)
408+
409+
fig.update_layout(
410+
title="Analytical Comparison",
411+
xaxis_title="Ratio of Hole Diameter to Width of Plate",
412+
yaxis_title="Stress Concentration",
413+
)
414+
415+
fig
416+
405417

406418
###############################################################################
407419
# Stop mapdl

0 commit comments

Comments
 (0)