Skip to content

Commit

Permalink
Bokeh SplinePlot handles multiple cubic splines (#1529)
Browse files Browse the repository at this point in the history
* Bokeh SplinePlot handles multiple cubic splines correctly

* Matplotlib SplinePlot handles empty Spline

* Simplified bokeh SplinePlot implementation
  • Loading branch information
philippjfr authored and jlstevens committed Jun 13, 2017
1 parent d42b031 commit 3251c83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 16 additions & 10 deletions holoviews/plotting/bokeh/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,20 @@ class SplinePlot(ElementPlot):
_plot_methods = dict(single='bezier')

def get_data(self, element, ranges=None, empty=False):
data_attrs = ['x0', 'y0', 'x1', 'y1',
'cx0', 'cx1', 'cy0', 'cy1']
if empty:
data = {attr: [] for attr in data_attrs}
else:
verts = np.array(element.data[0])
xs, ys = verts[:, 0], verts[:, 1]
data = dict(x0=[xs[0]], y0=[ys[0]], x1=[xs[-1]], y1=[ys[-1]],
cx0=[xs[1]], cy0=[ys[1]], cx1=[xs[2]], cy1=[ys[2]])

data_attrs = ['x0', 'y0', 'cx0', 'cy0', 'cx1', 'cy1', 'x1', 'y1',]
verts = np.array(element.data[0])
inds = np.where(np.array(element.data[1])==1)[0]
data = {da: [] for da in data_attrs}
skipped = False
for vs in np.split(verts, inds[1:]):
if len(vs) != 4:
skipped = len(vs) > 1
continue
for x, y, xl, yl in zip(vs[:, 0], vs[:, 1], data_attrs[::2], data_attrs[1::2]):
data[xl].append(x)
data[yl].append(y)
if skipped:
self.warning('Bokeh SplitPlot only support cubic splines, '
'unsupported splines were skipped during plotting.')
data = {da: data[da] for da in data_attrs}
return (data, dict(zip(data_attrs, data_attrs)))
2 changes: 2 additions & 0 deletions holoviews/plotting/mpl/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class SplinePlot(AnnotationPlot):

def draw_annotation(self, axis, data, opts):
verts, codes = data
if not len(verts):
return []
patch = patches.PathPatch(matplotlib.path.Path(verts, codes),
facecolor='none', **opts)
axis.add_patch(patch)
Expand Down

0 comments on commit 3251c83

Please sign in to comment.