def annotate(self, ax: plt.axes, x: np.array, y: np.array, labels: np.array) -> plt.axes: """ https://stackoverflow.com/questions/5147112/how-to-put-individual-tags-for-a-scatter-plot for more details Parameters ---------- ax x y labels Returns ------- """ for i, name in enumerate(labels): if name in self.points_to_annotate: ax.annotate(name, (x[i], y[i]), xytext=(-5, 10), textcoords='offset points', ha='center', va='bottom', bbox=dict(boxstyle='round,pad=0.5', fc='white', alpha=0.2)) return ax
def annotate_barh(ax: plt.axes, series: pd.Series, kwargs: Dict[str, Any]) -> None: # annotate the plot round_ = get_selected_item(kwargs, key='round', default=None) span = series.max() - series.min() inside = series.min() + span / 2.0 spacer = span / 150.0 for y, x in enumerate(series): xpos = x if x < inside else 0 color = "black" if xpos > 0 else "white" x = round(x, round_) if round_ else x ax.annotate(f"{x:,}", xy=(xpos + spacer, y), va="center", color=color, size="small") return None
def plot_gene_body( ax: plt.axes, gene: Mapping[str, Any], gene_model_height: float, vertical_offset: float = 0, ) -> None: """ Parameters ---------- ax gene gene_model_height vertical_offset Returns ------- """ gene_model_y = -gene_model_height + vertical_offset gene_rect = patches.Rectangle( xy=(1, gene_model_y), width=gene["length"], height=gene_model_height, facecolor="white", edgecolor="black", linewidth=1, ) ax.add_artist(gene_rect) if "domains" in gene: for domain in gene["domains"]: domain_width = domain["end"] - domain["start"] + 1 rect = patches.Rectangle( xy=(domain["start"], gene_model_y), width=domain_width, height=gene_model_height, facecolor=domain["color"], edgecolor="black", linewidth=1, ) ax.add_artist(rect) ax.annotate( s=domain["name"], xy=( domain["start"] + domain_width / 2, gene_model_y + gene_model_height / 2, ), ha="center", va="center", color=domain["textcolor"], ) if "endlabels" in gene: for endlabel in gene["endlabels"]: # spacing = gene["length"] * 0.01 # TODO: fix so that the labels match up across multiple gene models spacing = 10 if endlabel["side"] == "left": endlabel_x = -spacing endlabel_ha = "right" elif endlabel["side"] == "right": endlabel_x = gene["length"] + spacing endlabel_ha = "left" else: raise ValueError("endlabel side must be one of 'left' or 'right'") ax.annotate( s=endlabel["text"], xy=(endlabel_x, gene_model_y + gene_model_height / 2), ha=endlabel_ha, va="center", color=endlabel["textcolor"], )