def annotate_points_with_images(ax: plt.axes, indices: Union[List[int], np.ndarray], plot_data: np.ndarray, image_data: np.ndarray, image_size: Tuple[int, int], xybox: Tuple[float, float] = (-40., 40.)) -> None: """ Annotates a plot of points with converted image data. :param ax: A matplotlib axes object :param indices: A list of indices to index image data and plot data. :param plot_data: A 2D projection of image data. :param image_data: Original image data, where each row corresponds to an array of image data. :param image_size: A tuple representing image size in pixels. :return: None """ for i in indices: ab = AnnotationBbox( OffsetImage( image_data[i, :].reshape(image_size[0], image_size[1]), zoom=.8, cmap='gray' ), tuple(plot_data[i, :]), xybox=xybox, xycoords='data', boxcoords="offset points", pad=0.3, arrowprops=dict(arrowstyle="->")) ax.add_artist(ab)
def plot_cov(ax: plt.axes, mean: np.ndarray, cov_matrix: np.ndarray, color: str) -> None: # Helper function to visualize the distribution vals, vecs = np.linalg.eigh(cov_matrix) x, y = vecs[:, 0] theta = np.degrees(np.arctan2(y, x)) w, h = 2 * np.sqrt(vals) ax.add_artist(Ellipse(mean, w, h, theta, color=color, alpha=0.3))
def update_main_axes(axes: plt.axes, inside_circle: np.ndarray, outside_circle: np.ndarray, circle: plt.Circle, square: plt.Rectangle) -> None: """ Updates the main axes with the new information prior to taking a snapshot. """ axes.scatter(*(outside_circle.T), c="red", marker='.') axes.scatter(*(inside_circle.T), c="green", marker='.') axes.add_artist(circle) axes.add_artist(square)
def draw_one_situation(self, data: Data, calibration: CalibData, ax: plt.axes, vmax=None, vmin=None, title_prefix=""): """ Draw one situation with object on the graph. Args: data: Data object to be visualized calibration: CalibData object used for calibration ax: matplotlib.pyplot.axes object vmax: max value limit of the graph vmin: min value limit of the graph title_prefix: prefix for graph title Returns: im: matplotlib.image object """ obj = data obj.calc_delta_V(calibration) print(obj.x, obj.y, obj.z) capacitance = self.solver.solve(obj.delta_V) e_x, e_y, _ = self.get_COP(obj) im = self.solver.plot_map_in_detection_range(ax, capacitance, vmax=vmax, vmin=vmin) circle = plt.Circle((obj.x, obj.y), 13.5, color='#F55400', fill=False) circle_e = plt.Circle((e_x * 2000, e_y * 2000), 13.5, color='k', fill=False) ax.set_xlim(-100, 100) ax.set_ylim(-100, 100) ax.add_artist(circle) ax.add_artist(circle_e) ax.set_title(title_prefix + "(" + ",".join((str(obj.x), str(obj.y), str(obj.z))) + ")") ax.set_aspect('equal') return im
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"], )