Skip to content

Commit 82a55f2

Browse files
committed
add scatter_or_line argument to Learner1D.plot
1 parent e8dfd93 commit 82a55f2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

adaptive/learner/learner1D.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,22 +580,33 @@ def _loss(self, mapping, ival):
580580
loss = mapping[ival]
581581
return finite_loss(ival, loss, self._scale[0])
582582

583-
def plot(self):
583+
def plot(self, *, scatter_or_line=None):
584584
"""Returns a plot of the evaluated data.
585585
586586
Returns
587587
-------
588588
plot : `holoviews.element.Scatter` (if vdim=1)\
589589
else `holoviews.element.Path`
590590
Plot of the evaluated data.
591+
scatter_or_line : str, optional
592+
Plot as a scatter plot ("scatter") or a line plot ("line").
593+
By default a line plot will be chosen if the data consists of
594+
vectors, otherwise it is a scatter plot.
591595
"""
592596
hv = ensure_holoviews()
593597

594598
xs, ys = zip(*sorted(self.data.items())) if self.data else ([], [])
595599
if self.vdim == 1:
596-
p = hv.Path([]) * hv.Scatter((xs, ys))
600+
if scatter_or_line is None or scatter_or_line == "scatter":
601+
p = hv.Path([]) * hv.Scatter((xs, ys))
602+
else:
603+
p = hv.Path((xs, ys)) * hv.Scatter()
597604
else:
598-
p = hv.Path((xs, ys)) * hv.Scatter([])
605+
if scatter_or_line is None or scatter_or_line == "line":
606+
p = hv.Path((xs, ys)) * hv.Scatter([])
607+
else:
608+
scatters = [hv.Scatter((xs, _ys)) for _ys in np.transpose(ys)]
609+
p = hv.Path([]) * hv.Overlay(scatters)
599610

600611
# Plot with 5% empty margins such that the boundary points are visible
601612
margin = 0.05 * (self.bounds[1] - self.bounds[0])

0 commit comments

Comments
 (0)