def _draw_markers(self, plot, element, marks, axis='x'): if marks is None: return style = self.style[self.cyclic_index] mark_opts = {k[7:]: v for k, v in style.items() if axis + 'mark' in k} mark_opts = { 'line_' + k if k in ('color', 'alpha') else k: v for k, v in mpl_to_bokeh(mark_opts).items() } categories = list( element.dimension_values(0 if axis == 'x' else 1, expanded=False)) if callable(marks): positions = [i for i, x in enumerate(categories) if marks(x)] elif isinstance(marks, int): nth_mark = np.ceil(len(categories) / marks).astype(int) positions = np.arange(len(categories) + 1)[::nth_mark] elif isinstance(marks, tuple): positions = [categories.index(m) for m in marks if m in categories] else: positions = [ m for m in marks if isinstance(m, int) and m < len(categories) ] if axis == 'y': positions = [len(categories) - p for p in positions] prev_markers = self.handles.get(axis + 'marks', []) new_markers = [] for i, p in enumerate(positions): if i < len(prev_markers): span = prev_markers[i] span.update(**dict(mark_opts, location=p)) else: dimension = 'height' if axis == 'x' else 'width' span = Span(level='annotation', dimension=dimension, location=p, **mark_opts) plot.renderers.append(span) span.visible = True new_markers.append(span) for pm in prev_markers: if pm not in new_markers: pm.visible = False new_markers.append(pm) self.handles[axis + 'marks'] = new_markers
def _draw_markers(self, plot, element, marks, axis='x'): if marks is None: return style = self.style[self.cyclic_index] mark_opts = {k[7:]: v for k, v in style.items() if axis+'mark' in k} mark_opts = {'line_'+k if k in ('color', 'alpha') else k: v for k, v in mpl_to_bokeh(mark_opts).items()} categories = list(element.dimension_values(0 if axis == 'x' else 1, expanded=False)) if callable(marks): positions = [i for i, x in enumerate(categories) if marks(x)] elif isinstance(marks, int): nth_mark = np.ceil(len(categories) / marks).astype(int) positions = np.arange(len(categories)+1)[::nth_mark] elif isinstance(marks, tuple): positions = [categories.index(m) for m in marks if m in categories] else: positions = [m for m in marks if isinstance(m, int) and m < len(categories)] if axis == 'y': positions = [len(categories)-p for p in positions] prev_markers = self.handles.get(axis+'marks', []) new_markers = [] for i, p in enumerate(positions): if i < len(prev_markers): span = prev_markers[i] span.update(**dict(mark_opts, location=p)) else: dimension = 'height' if axis == 'x' else 'width' span = Span(level='annotation', dimension=dimension, location=p, **mark_opts) plot.renderers.append(span) span.visible = True new_markers.append(span) for pm in prev_markers: if pm not in new_markers: pm.visible = False new_markers.append(pm) self.handles[axis+'marks'] = new_markers
def draw_figure(self, **kwargs): y_axis_type = kwargs.pop('y_axis_type', 'log') x_axis_type = kwargs.pop('x_axis_type', 'linear') fig = figure(y_axis_type=y_axis_type, x_axis_type=x_axis_type, tools='pan,wheel_zoom,box_zoom,save,reset', **kwargs) fig.min_border_left = MIN_BORDER_LEFT fig.xaxis.axis_label = 'Residue number' fig.yaxis.axis_label = self.y_label # todo refactor controller access to imporove upon current try/except and allow more controller agnostic behaviour try: for _ in range(self.control_panels['ClassificationControl']. param['num_colors'].bounds[1] - 1): sp = Span(location=0, dimension='width') sp.tags = ['thd'] sp.visible = False fig.add_layout(sp) except KeyError: pass return fig