Skip to content
Snippets Groups Projects

Resolve "(LearnerND) add iso-surface plot feature"

Merged Jorn Hoofwijk requested to merge 112-learnernd-add-iso-surface-plot-feature into master
All threads resolved!
1 file
+ 65
2
Compare changes
  • Side-by-side
  • Inline
@@ -645,7 +645,7 @@ class LearnerND(BaseLearner):
)
return vertices, faces
def _get_isoline(self, level=0.0):
# Very similar to _get_isosurface, maybe merge the two functions
if self.ndim != 2 or self.vdim != 1:
@@ -723,7 +723,7 @@ class LearnerND(BaseLearner):
plot = hv.Path([])
else:
plot = self.plot(n=n, tri_alpha=tri_alpha)
if isinstance(level, Iterable):
for l in level:
plot = plot * self.plot_isoline(level=l, n=-1)
@@ -804,3 +804,66 @@ class LearnerND(BaseLearner):
return plotly.graph_objs.Mesh3d(x=x, y=y, z=z, i=i, j=j, k=k,
facecolor=colors, opacity=opacity,
lighting=lighting)
def plot_3D(self, with_triangulation=True):
"""Plot the learner's data in 3D using plotly.
Parameters
----------
with_triangulation : bool, default: True
Add the verticices to the plot.
Returns
-------
plot : plotly.offline.iplot object
The 3D plot of ``learner.data``.
"""
plotly = ensure_plotly()
plots = []
vertices = self.tri.vertices
if with_triangulation:
Xe, Ye, Ze = [], [], []
for simplex in self.tri.simplices:
for s in itertools.combinations(simplex, 2):
Xe += [vertices[i][0] for i in s] + [None]
Ye += [vertices[i][1] for i in s] + [None]
Ze += [vertices[i][2] for i in s] + [None]
plots.append(plotly.graph_objs.Scatter3d(
x=Xe, y=Ye, z=Ze, mode='lines',
line=dict(color='rgb(125,125,125)', width=1),
hoverinfo='none'
))
Xn, Yn, Zn = zip(*vertices)
colors = [self.data[p] for p in self.tri.vertices]
marker = dict(symbol='circle', size=3, color=colors,
colorscale='Viridis',
line=dict(color='rgb(50,50,50)', width=0.5))
plots.append(plotly.graph_objs.Scatter3d(
x=Xn, y=Yn, z=Zn, mode='markers',
name='actors', marker=marker,
hoverinfo='text'
))
axis = dict(
showbackground=False,
showline=False,
zeroline=False,
showgrid=False,
showticklabels=False,
title='',
)
layout = plotly.graph_objs.Layout(
showlegend=False,
scene=dict(xaxis=axis, yaxis=axis, zaxis=axis),
margin=dict(t=100),
hovermode='closest')
fig = plotly.graph_objs.Figure(data=plots, layout=layout)
return plotly.offline.iplot(fig)
Loading