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
Changes from 2 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+24 −9
Diff settings

Always

Just for now

@@ -88,13 +88,26 @@ class SplinePlot(ElementPlot):

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]])

'cx0', 'cy0', 'cx1', 'cy1']
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
xs, ys = vs[:, 0], vs[:, 1]

This comment has been minimized.

Copy link
@jlstevens

jlstevens Jun 12, 2017

Contributor

Maybe zip the string keys and values and loop over them to append?

data['x0'].append(xs[0])
data['y0'].append(ys[0])
data['x1'].append(xs[-1])
data['y1'].append(ys[-1])
data['cx0'].append(xs[1])
data['cy0'].append(ys[1])
data['cx1'].append(xs[2])
data['cy1'].append(ys[2])
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)))
@@ -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)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.