def _plot_hlines(self, obj): hlines = obj.plotinfo._get('plothlines', []) if not hlines: hlines = obj.plotinfo._get('plotyhlines', []) # Horizontal Lines hline_color = convert_color(self._scheme.hlinescolor) for hline in hlines: span = Span(location=hline, dimension='width', line_color=hline_color, line_dash=convert_linestyle(self._scheme.hlinesstyle), line_width=self._scheme.hlineswidth) self.figure.renderers.append(span)
def _plot_indicator_observer(self, obj: Union[bt.Indicator, bt.Observer]): pl = labelizer.label(obj) self._figure_append_title(pl) indlabel = obj.plotlabel() plotinfo = obj.plotinfo is_multiline = obj.size() > 1 for lineidx in range(obj.size()): line = obj.lines[lineidx] source_id = get_source_id(line) linealias = obj.lines._getlinealias(lineidx) lineplotinfo = get_plotlineinfo(obj, lineidx) if lineplotinfo._get('_plotskip', False): continue method = lineplotinfo._get('_method', 'line') color = getattr(lineplotinfo, 'color', None) if color is None: if not lineplotinfo._get('_samecolor', False): self._nextcolor() color = self._color() color = convert_color(color) kwglyphs = {'name': linealias} self._add_column(source_id, np.float64) # either all individual lines of are displayed in the legend or only the ind/obs as a whole label = indlabel if is_multiline and plotinfo.plotlinelabels: label += " " + (lineplotinfo._get("_name", "") or linealias) kwglyphs['legend_label'] = label marker = lineplotinfo._get('marker', None) if marker is not None: fnc_name, extra_kwglyphs = build_marker_call(marker, self.bfigure, source_id, color, lineplotinfo.markersize) kwglyphs.update(extra_kwglyphs) glyph_fnc = getattr(self.bfigure, fnc_name) elif method == "bar": kwglyphs['bottom'] = 0 kwglyphs['line_color'] = 'black' kwglyphs['fill_color'] = color kwglyphs['width'] = get_bar_width() kwglyphs['top'] = source_id glyph_fnc = self.bfigure.vbar elif method == "line": kwglyphs['line_width'] = 1 kwglyphs['color'] = color kwglyphs['y'] = source_id linestyle = getattr(lineplotinfo, "ls", None) if linestyle is not None: kwglyphs['line_dash'] = convert_linestyle(linestyle) linewidth = getattr(lineplotinfo, "lw", None) if linewidth is not None: kwglyphs['line_width'] = linewidth glyph_fnc = self.bfigure.line else: raise Exception(f"Unknown plotting method '{method}'") renderer = glyph_fnc("index", source=self._cds, **kwglyphs) # iterate again to generate area plot data for fattr, y1, y2, fcol, falpha, fop in get_ind_areas(obj, lineidx): self._add_column(y1, np.float64) falpha = falpha or self._scheme.fillalpha fcol = convert_color(fcol) self.bfigure.varea('index', source=self._cds, y1=y1, y2=y2, fill_color=fcol, fill_alpha=falpha) # make sure the regular y-axis only scales to the normal data (data + ind/obs) on 1st axis (not to e.g. volume data on 2nd axis) self.bfigure.y_range.renderers.append(renderer) # for markers add additional renderer so hover pops up for all of them if marker is None: self._set_single_hover_renderer(renderer) else: self._add_hover_renderer(renderer) hover_label_suffix = f" - {linealias}" if obj.size() > 1 else "" # we need no suffix if there is just one line in the indicator anyway hover_label = indlabel + hover_label_suffix hover_data = f"@{source_id}{{{self._scheme.number_format}}}" self._hoverc.add_hovertip(hover_label, hover_data, obj) self._set_yticks(obj) self._plot_hlines(obj)
def _plot_indicator_observer(self, obj: Union[bt.Indicator, bt.Observer], master, strat_clk: array = None): pl = plotobj2label(obj) self._figure_append_title(pl) indlabel = obj.plotlabel() plotinfo = obj.plotinfo for lineidx in range(obj.size()): line = obj.lines[lineidx] source_id = Figure._source_id(line) linealias = obj.lines._getlinealias(lineidx) lineplotinfo = getattr(obj.plotlines, '_%d' % lineidx, None) if not lineplotinfo: lineplotinfo = getattr(obj.plotlines, linealias, None) if not lineplotinfo: lineplotinfo = bt.AutoInfoClass() if lineplotinfo._get('_plotskip', False): continue marker = lineplotinfo._get("marker", None) method = lineplotinfo._get('_method', "line") color = getattr(lineplotinfo, "color", None) if color is None: if not lineplotinfo._get('_samecolor', False): self._nextcolor() color = self._color() color = convert_color(color) kwglyphs = {'name': linealias} dataline = line.plotrange(self._start, self._end) line_clk = get_data_obj(obj).lines.datetime.plotrange( self._start, self._end) dataline = resample_line(dataline, line_clk, strat_clk) self._add_to_cds(dataline, source_id) label = None if master is None or lineidx == 0 or plotinfo.plotlinelabels: label = indlabel if master is None or plotinfo.plotlinelabels: label += " " + (lineplotinfo._get("_name", "") or linealias) kwglyphs['legend_label'] = label if marker is not None: kwglyphs['size'] = lineplotinfo.markersize * 1.2 kwglyphs['color'] = color kwglyphs['y'] = source_id mrk_fncs = { '^': self.figure.triangle, 'v': self.figure.inverted_triangle, 'o': self.figure.circle, '<': self.figure.circle_cross, '>': self.figure.circle_x, '1': self.figure.diamond, '2': self.figure.diamond_cross, '3': self.figure.hex, '4': self.figure.square, '8': self.figure.square_cross, 's': self.figure.square_x, 'p': self.figure.triangle, '*': self.figure.asterisk, 'h': self.figure.hex, 'H': self.figure.hex, '+': self.figure.asterisk, 'x': self.figure.x, 'D': self.figure.diamond_cross, 'd': self.figure.diamond, } if marker not in mrk_fncs: raise Exception( f"Sorry, unsupported marker: '{marker}'. Please report to GitHub." ) glyph_fnc = mrk_fncs[marker] elif method == "bar": kwglyphs['bottom'] = 0 kwglyphs['line_color'] = 'black' kwglyphs['fill_color'] = color kwglyphs['width'] = get_bar_width() kwglyphs['top'] = source_id glyph_fnc = self.figure.vbar elif method == "line": kwglyphs['line_width'] = 1 kwglyphs['color'] = color kwglyphs['y'] = source_id linestyle = getattr(lineplotinfo, "ls", None) if linestyle is not None: kwglyphs['line_dash'] = convert_linestyle(linestyle) glyph_fnc = self.figure.line else: raise Exception(f"Unknown plotting method '{method}'") renderer = glyph_fnc("index", source=self._cds, **kwglyphs) # for markers add additional renderer so hover pops up for all of them if marker is None: self._set_single_hover_renderer(renderer) else: self._add_hover_renderer(renderer) hover_label_suffix = f" - {linealias}" if obj.size( ) > 1 else "" # we need no suffix if there is just one line in the indicator anyway hover_label = indlabel + hover_label_suffix hover_data = f"@{source_id}{{{self._scheme.number_format}}}" self._hoverc.add_hovertip(hover_label, hover_data, obj) # adapt y-axis if needed if master is None or getattr(master.plotinfo, 'plotylimited', False) is False: adapt_yranges(self.figure.y_range, dataline) self._set_yticks(obj) self._plot_hlines(obj)
def _plot_indicator_observer(self, obj: Union[bt.Indicator, bt.Observer], master): # pl = plotobj2label(obj) pl = "" self._figure_append_title(pl) indlabel = obj.plotlabel() plotinfo = obj.plotinfo is_multiline = obj.size() > 1 for lineidx in range(obj.size()): line = obj.lines[lineidx] source_id = FigureEnvelope._source_id(line) linealias = obj.lines._getlinealias(lineidx) lineplotinfo = getattr(obj.plotlines, '_%d' % lineidx, None) if not lineplotinfo: lineplotinfo = getattr(obj.plotlines, linealias, None) if not lineplotinfo: lineplotinfo = bt.AutoInfoClass() if lineplotinfo._get('_plotskip', False): continue marker = lineplotinfo._get("marker", None) method = lineplotinfo._get('_method', "line") color = getattr(lineplotinfo, "color", None) if color is None: if not lineplotinfo._get('_samecolor', False): self._nextcolor() color = self._color() color = convert_color(color) kwglyphs = {'name': linealias} self._add_column(source_id, np.float64) # either all individual lines of are displayed in the legend or only the ind/obs as a whole label = indlabel if is_multiline and plotinfo.plotlinelabels: label += " " + (lineplotinfo._get("_name", "") or linealias) kwglyphs['legend_label'] = label if marker is not None: kwglyphs['size'] = lineplotinfo.markersize * 1.2 kwglyphs['color'] = color kwglyphs['y'] = source_id if marker not in FigureEnvelope._mrk_fncs: raise Exception(f"Sorry, unsupported marker: '{marker}'. Please report to GitHub.") glyph_fnc_name = FigureEnvelope._mrk_fncs[marker] glyph_fnc = getattr(self.figure, glyph_fnc_name) elif method == "bar": kwglyphs['bottom'] = 0 kwglyphs['line_color'] = 'black' kwglyphs['fill_color'] = color kwglyphs['width'] = get_bar_width() kwglyphs['top'] = source_id glyph_fnc = self.figure.vbar elif method == "line": kwglyphs['line_width'] = 1 kwglyphs['color'] = color kwglyphs['y'] = source_id linestyle = getattr(lineplotinfo, "ls", None) if linestyle is not None: kwglyphs['line_dash'] = convert_linestyle(linestyle) glyph_fnc = self.figure.line else: raise Exception(f"Unknown plotting method '{method}'") renderer = glyph_fnc("index", source=self._cds, **kwglyphs) # make sure the regular y-axis only scales to the normal data (data + ind/obs) on 1st axis (not to e.g. volume data on 2nd axis) self.figure.y_range.renderers.append(renderer) # for markers add additional renderer so hover pops up for all of them if marker is None: self._set_single_hover_renderer(renderer) else: self._add_hover_renderer(renderer) hover_label_suffix = f" - {linealias}" if obj.size() > 1 else "" # we need no suffix if there is just one line in the indicator anyway hover_label = indlabel + hover_label_suffix hover_data = f"@{source_id}{{{self._scheme.number_format}}}" # self._hoverc.add_hovertip(hover_label, hover_data, obj) self._set_yticks(obj) self._plot_hlines(obj)