diff --git a/doc/changelog.d/2346.documentation.md b/doc/changelog.d/2346.documentation.md new file mode 100644 index 0000000000..67e5fbef3d --- /dev/null +++ b/doc/changelog.d/2346.documentation.md @@ -0,0 +1 @@ +docs: adding plottly support to gallery examples \ No newline at end of file diff --git a/doc/source/conf.py b/doc/source/conf.py index 47a3f595da..e14000634e 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -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__ @@ -276,7 +280,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, @@ -355,6 +363,8 @@ html_show_sourcelink = False +html_js_files = ["https://cdn.plot.ly/plotly-3.0.1.min.js"] + # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. diff --git a/examples/00-mapdl-examples/2d_plate_with_a_hole.py b/examples/00-mapdl-examples/2d_plate_with_a_hole.py index 2f074a054e..b4154eea21 100644 --- a/examples/00-mapdl-examples/2d_plate_with_a_hole.py +++ b/examples/00-mapdl-examples/2d_plate_with_a_hole.py @@ -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 @@ -396,12 +396,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