Skip to content

Commit 187f88f

Browse files
authored
Merge pull request #215 from python-adaptive/learner1D_plot
add scatter_or_line argument to Learner1D.plot
2 parents e8dfd93 + 62a7d6b commit 187f88f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

adaptive/learner/learner1D.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,23 +580,35 @@ 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="scatter"):
584584
"""Returns a plot of the evaluated data.
585585
586+
Parameters
587+
----------
588+
scatter_or_line : str, default: "scatter"
589+
Plot as a scatter plot ("scatter") or a line plot ("line").
590+
586591
Returns
587592
-------
588-
plot : `holoviews.element.Scatter` (if vdim=1)\
589-
else `holoviews.element.Path`
593+
plot : `holoviews.Overlay`
590594
Plot of the evaluated data.
591595
"""
596+
if scatter_or_line not in ("scatter", "line"):
597+
raise ValueError("scatter_or_line must be 'scatter' or 'line'")
592598
hv = ensure_holoviews()
593599

594600
xs, ys = zip(*sorted(self.data.items())) if self.data else ([], [])
595-
if self.vdim == 1:
596-
p = hv.Path([]) * hv.Scatter((xs, ys))
601+
if scatter_or_line == "scatter":
602+
if self.vdim == 1:
603+
plots = [hv.Scatter((xs, ys))]
604+
else:
605+
plots = [hv.Scatter((xs, _ys)) for _ys in np.transpose(ys)]
597606
else:
598-
p = hv.Path((xs, ys)) * hv.Scatter([])
607+
plots = [hv.Path((xs, ys))]
599608

609+
# Put all plots in an Overlay because a DynamicMap can't handle changing
610+
# datatypes, e.g. when `vdim` isn't yet known and the live_plot is running.
611+
p = hv.Overlay(plots)
600612
# Plot with 5% empty margins such that the boundary points are visible
601613
margin = 0.05 * (self.bounds[1] - self.bounds[0])
602614
plot_bounds = (self.bounds[0] - margin, self.bounds[1] + margin)

0 commit comments

Comments
 (0)