Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding plottly support to gallery examples #2346

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2346.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adding plottly support to gallery examples
10 changes: 9 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
import ansys.tools.visualization_interface as viz_interface
from ansys_sphinx_theme import ansys_favicon, get_version_match
import numpy as np
import plotly.io as pio
from plotly.io._sg_scraper import plotly_sg_scraper
import pyvista
from sphinx.application import Sphinx
from sphinx.util import logging
from sphinx_gallery.sorting import FileNameSortKey

pio.renderers.default = "sphinx_gallery"

from ansys.mapdl import core as pymapdl
from ansys.mapdl.core import __version__

Expand Down Expand Up @@ -270,7 +274,11 @@
"backreferences_dir": None,
# Modules for which function level galleries are created. In
"doc_module": "ansys-mapdl-core",
"image_scrapers": ("pyvista", "matplotlib"),
"image_scrapers": (
"pyvista",
"matplotlib",
plotly_sg_scraper,
),
"ignore_pattern": "flycheck*",
"thumbnail_size": (350, 350),
"remove_config_comments": True,
Expand Down
26 changes: 19 additions & 7 deletions examples/00-mapdl-examples/2d_plate_with_a_hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"""
# sphinx_gallery_thumbnail_number = 3

import matplotlib.pyplot as plt
import numpy as np
import plotly.graph_objects as go

from ansys.mapdl.core import launch_mapdl

Expand Down Expand Up @@ -397,12 +397,24 @@ def compute_stress_con(ratio):
# where ratio is (d/h)
k_t_anl = 3 - 3.14 * ratios + 3.667 * ratios**2 - 1.527 * ratios**3

plt.plot(ratios, k_t_anl, label=r"$K_t$ Analytical")
plt.plot(ratios, k_t_exp, label=r"$K_t$ ANSYS")
plt.legend()
plt.xlabel("Ratio of Hole Diameter to Width of Plate")
plt.ylabel("Stress Concentration")
plt.show()

# Create traces
fig = go.Figure()
fig.add_trace(
go.Scatter(x=ratios, y=k_t_anl, mode="lines", name=r"$K_t \text{ Analytical}$")
)
fig.add_trace(
go.Scatter(x=ratios, y=k_t_exp, mode="lines+markers", name=r"$K_t \text{ ANSYS}$")
)

fig.update_layout(
title="Analytical Comparison",
xaxis_title="Ratio of Hole Diameter to Width of Plate",
yaxis_title="Stress Concentration",
)

fig


###############################################################################
# Stop mapdl
Expand Down
Loading