Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bokeh SplinePlot handles multiple cubic splines #1529

Merged
merged 3 commits into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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