Skip to content

Commit 905bb42

Browse files
committed
take out a cut from the 3D sphere, LearnerND example
1 parent e655186 commit 905bb42

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

adaptive/learner/learnerND.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ def plot_slice(self, cut_mapping, n=None):
909909
else:
910910
raise ValueError("Only 1 or 2-dimensional plots can be generated.")
911911

912-
def plot_3D(self, with_triangulation=False):
912+
def plot_3D(self, with_triangulation=False, return_fig=False):
913913
"""Plot the learner's data in 3D using plotly.
914914
915915
Does *not* work with the
@@ -919,6 +919,9 @@ def plot_3D(self, with_triangulation=False):
919919
----------
920920
with_triangulation : bool, default: False
921921
Add the verticices to the plot.
922+
return_fig : bool, default: False
923+
Return the `plotly.graph_objs.Figure` object instead of showing
924+
the rendered plot (default).
922925
923926
Returns
924927
-------
@@ -989,7 +992,7 @@ def plot_3D(self, with_triangulation=False):
989992

990993
fig = plotly.graph_objs.Figure(data=plots, layout=layout)
991994

992-
return plotly.offline.iplot(fig)
995+
return fig if return_fig else plotly.offline.iplot(fig)
993996

994997
def _get_iso(self, level=0.0, which="surface"):
995998
if which == "surface":

docs/source/docs.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,20 @@ on the *Play* :fa:`play` button or move the sliders.
149149
learner = adaptive.LearnerND(sphere, bounds=[(-1, 1), (-1, 1), (-1, 1)])
150150
adaptive.runner.simple(learner, lambda l: l.npoints == 3000)
151151

152-
learner.plot_3D()
152+
fig = learner.plot_3D()
153+
154+
# Remove a slice from the plot to show the inside of the sphere
155+
scatter = fig.data[0]
156+
coords_col = [
157+
(x, y, z, color)
158+
for x, y, z, color in zip(
159+
scatter["x"], scatter["y"], scatter["z"], scatter.marker["color"]
160+
)
161+
if not (x > 0 and y > 0)
162+
]
163+
scatter["x"], scatter["y"], scatter["z"], scatter.marker["color"] = zip(*coords_col)
164+
165+
fig
153166

154167
see more in the :ref:`Tutorial Adaptive`.
155168

0 commit comments

Comments
 (0)