def pass_arrow(loc0, loc1): import matplotlib.patches as patches style = patches.ArrowStyle('->', head_length=5, head_width=5) connection = patches.ConnectionStyle("Arc3", rad=0) arrow = patches.FancyArrowPatch(tuple(loc0), tuple(loc1), arrowstyle=style, connectionstyle=connection, linestyle='-') return arrow
def carry_arrow(loc0, loc1): import matplotlib.patches as patches style = patches.ArrowStyle('-') connection = patches.ConnectionStyle("Arc3", rad=0) arrow = patches.FancyArrowPatch(tuple(loc0), tuple(loc1), arrowstyle=style, connectionstyle=connection, linestyle='--') return arrow
def plot_network(self, scen_index=None, show_title=True, randomize_txt_box=True, figsize=(6, 5), path=None, extension=".pdf"): fig, ax = plt.subplots(figsize=figsize) N = len(self.stochastic_problem.vertices) pos = { vertex: np.exp(2 * np.pi * 1j * k / N) for k, vertex in enumerate(self.stochastic_problem.vertices, 1) } pos = {key: (value.real, value.imag) for key, value in pos.items()} # Plot vertices for vertex in self.stochastic_problem.vertices: label = self._vertex_label( vertex, scen_index) if scen_index is not None else None ax.scatter(*pos[vertex], c=self._vertex_color(vertex), s=150, alpha=0.8, label=label) ax.text(*pos[vertex], vertex, horizontalalignment='center', verticalalignment='center') # Plot arcs for arc in self.stochastic_problem.all_arcs: a = patches.FancyArrowPatch(pos[arc[0]], pos[arc[1]], connectionstyle="arc3,rad=.05", **self._arc_style(arc, scen_index)) fig.gca().add_patch(a) if scen_index is not None: self._print_transportated_value(arc, scen_index, randomize_txt_box, pos, ax) if scen_index is not None: ax.legend(bbox_to_anchor=(1, 1.15), loc=1, borderaxespad=1, prop={'size': 7}) if show_title: if scen_index is None: obj_to_show = self.objective_value ax.set_title(f"$v^*: {obj_to_show:.2f}$") else: obj_to_show = self.objective_value_at_leaves[scen_index] ax.set_title(f"$v^*: {obj_to_show:.2f}$") ax.axis('off') self._save_fig(path, extension) fig.show()
def get_arrow(arrow_length, arrow_width, arrow_courve, arrow_color, future_arrow_curve): # x_tail = 0.5 # y_tail = 0.16 # # x_head = x_tail+arrow_courve-0.5 # y_head = y_tail+arrow_length # dx = x_head - x_tail # dy = y_head - y_tail # fig, axs = plt.subplots() axs.set_xlim(-.5, 0.5) axs.set_ylim(0, 1.25) # arrow = mpatches.Arrow(x_tail, y_tail, dx, dy, width=arrow_width, color=arrow_color) style = ("Simple,tail_width=" + str(50) + ",head_width=" + str(100) + ",head_length=" + str(30)) kw = dict(arrowstyle=style, color=arrow_color) arrow = mpatches.FancyArrowPatch( (0, 0), ((arrow_courve - 0.5), 0.3 + arrow_length * 1.25), connectionstyle=("arc3,rad=" + str(-1 * (arrow_courve - 0.5))), **kw) style2 = ("Simple,tail_width=" + str(50) + ",head_width=" + str(100) + ",head_length=" + str(30)) kw2 = dict(arrowstyle=style2, color='k', fill=False, linestyle='dashed') arrow2 = mpatches.FancyArrowPatch( (0, 0), ((future_arrow_curve - 0.5), 0.3 + arrow_length * 1.25), connectionstyle=("arc3,rad=" + str(-1 * (arrow_courve - 0.5))), **kw2) axs.add_patch(arrow2) axs.add_patch(arrow) axs.set_axis_off() fig.add_axes(axs) fig.canvas.draw() # Now we can save it to a numpy array. data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='') data = data.reshape(fig.canvas.get_width_height()[::-1] + (3, )) return data
def add_arrow(ax, tailhead, **kwargs): arrowDict = dict(linewidth=1., color='k', arrowstyle='-|>', mutation_scale=12 * 1) arrowDict.update(kwargs) p = patches.FancyArrowPatch(tailhead[0], tailhead[1], transform=ax.transData, **arrowDict) ax.add_patch(p)
def annotate_angle(ax, text, xloc, line, hline, buf=50): """Annotate angle between two given lines.""" posA, posB = Point(xloc, line.y(xloc)), Point(xloc, hline.y(xloc)) arrowstyle = '<->,head_length=5,head_width=3' arrow = patches.FancyArrowPatch(posA=(posA.x, posA.y), posB=(posB.x, posB.y), arrowstyle=arrowstyle, color='black', linewidth=2.0, connectionstyle='arc3,rad=-0.5') ax.add_patch(arrow) ax.annotate(text, xy=(xloc + buf, get_midpoint(posA, posB).y))
def shot_arrow(loc0, loc1): style = patches.ArrowStyle('-|>', head_length=2, head_width=2) connection = patches.ConnectionStyle("Arc3", rad=0) arrow = patches.FancyArrowPatch(tuple(loc0), tuple(loc1), arrowstyle=style, connectionstyle=connection, linestyle='-', color='red', linewidth=2) return arrow
def mkarrow(start, end, curved=False, **kwargs): alpha = kwargs.pop('alpha', 0.8) return patches.FancyArrowPatch( start, end, arrowstyle="Simple,tail_width=0.5,head_width=4,head_length=8", connectionstyle="arc3,rad=.2" if curved > 0 else "arc3,rad=-.2" if curved < 0 else None, alpha=alpha, **kwargs, )
def add_arrow_to_line2D( axes, line, arrow_locs=[0.2, 0.4, 0.6, 0.8], arrowstyle='-|>', arrowsize=1, transform=None): """ Add arrows to a matplotlib.lines.Line2D at selected locations. Parameters: ----------- axes: line: list of 1 Line2D obbject as returned by plot command arrow_locs: list of locations where to insert arrows, % of total length arrowstyle: style of the arrow arrowsize: size of the arrow transform: a matplotlib transform instance, default to data coordinates Returns: -------- arrows: list of arrows """ if (not(isinstance(line, list)) or not(isinstance(line[0], mlines.Line2D))): raise ValueError("expected a matplotlib.lines.Line2D object") x, y = line[0].get_xdata(), line[0].get_ydata() arrow_kw = dict(arrowstyle=arrowstyle, mutation_scale=10 * arrowsize) color = line[0].get_color() use_multicolor_lines = isinstance(color, np.ndarray) if use_multicolor_lines: raise NotImplementedError("multicolor lines not supported") else: arrow_kw['color'] = color linewidth = line[0].get_linewidth() if isinstance(linewidth, np.ndarray): raise NotImplementedError("multiwidth lines not supported") else: arrow_kw['linewidth'] = linewidth if transform is None: transform = axes.transData arrows = [] for loc in arrow_locs: s = np.cumsum(np.sqrt(np.diff(x) ** 2 + np.diff(y) ** 2)) n = np.searchsorted(s, s[-1] * loc) arrow_tail = (x[n], y[n]) arrow_head = (np.mean(x[n:n + 2]), np.mean(y[n:n + 2])) p = mpatches.FancyArrowPatch( arrow_tail, arrow_head, transform=transform, **arrow_kw) axes.add_patch(p) arrows.append(p) return arrows
def _make_arrow(self, pos, col, str, ax): kw = dict(arrowstyle="Simple,tail_width=1,head_width=8,head_length=8", color=col) dist = np.linalg.norm(pos[1] - pos[0]) eps = self.areaRad / dist posPrim = [(1 - eps) * pos[0] + eps * pos[1], eps * pos[0] + (1 - eps) * pos[1]] arrow123 = patches.FancyArrowPatch( posPrim[0], posPrim[1], **kw) # , connectionstyle="arc3,rad=.5 ax.add_patch(arrow123)
def create_edge_patch(posA, posB, node_rad=0, connectionstyle='arc3, rad=0.25', facecolor='k', head_length=10, head_width=10, tail_width=3, **kwargs): style = "simple,head_length=%d,head_width=%d,tail_width=%d"%(head_length, head_width, tail_width) return pat.FancyArrowPatch(posA=posA, posB=posB, arrowstyle=style, connectionstyle=connectionstyle, facecolor=facecolor, shrinkA=node_rad, shrinkB=node_rad, **kwargs)
def add_robot_orientation(self): theta = np.arctan2(self.frames[0][0].vy, self.frames[0][0].vx) orientation = ((0, 0), (self.frames[0][0].radius * np.cos(theta), self.frames[0][0].radius * np.sin(theta))) self.robot_ori = patches.FancyArrowPatch(*orientation, color='r', arrowstyle=patches.ArrowStyle( "->", head_length=4, head_width=2)) self.ax.add_artist(self.robot_ori)
def _get_patch(self, s: float) -> patches.Patch: label = "Thin Sextupole" colour = "tab:green" return patches.FancyArrowPatch( (s, 1), (s, -1), arrowstyle=patches.ArrowStyle("|-|"), label=label, edgecolor=colour, facecolor=colour, )
def update(frame_num): nonlocal global_step nonlocal arrows global_step = frame_num robot.center = robot_positions[frame_num] for i, human in enumerate(humans): human.center = human_positions[frame_num][i] if display_numbers: human_numbers[i].set_position( (human.center[0] - x_offset, human.center[1] + y_offset)) for arrow in arrows: arrow.remove() for i in range(self.human_num + 1): orientation = orientations[i] if i == 0: arrows = [ patches.FancyArrowPatch(*orientation[frame_num], color='black', arrowstyle=arrow_style) ] else: arrows.extend([ patches.FancyArrowPatch(*orientation[frame_num], color=cmap(i - 1), arrowstyle=arrow_style) ]) for arrow in arrows: ax.add_artist(arrow) # if hasattr(self.robot.policy, 'get_attention_weights'): # attention_scores[i].set_text('human {}: {:.2f}'.format(i, self.attention_weights[frame_num][i])) time.set_text('Time: {:.2f}'.format(frame_num * self.time_step)) reward.set_text('Reward: {:.2f}'.format( self.rewards[frame_num])) reward_sum.set_text('Reward Sum: {:.2f}'.format( sum(self.rewards[0:frame_num])))
def recurrent_connect(idx=180, n_arrows=40, i0_arrows=5, step_arrows=3, color=e_color, xs=e_xs, ys=e_ys, yfrom_rectif=0., yto_rectif=-.03): ''' Draws recurrent synapses using arc FancyArrowPatch ''' style = "Simple,tail_width=0.2,head_width=2,head_length=2" kw = dict(arrowstyle=style, edgecolor=color) alphas = 1 / np.exp(np.linspace(0., 2.5 * np.e, n_arrows)) lspace = np.linspace(i0_arrows, n_arrows, n_arrows // step_arrows, dtype=int) # Forward for i0, x in enumerate(lspace): arr = patches.FancyArrowPatch((xs[idx], ys[idx] + yfrom_rectif), (xs[idx + x], ys[idx + x] + yto_rectif), facecolor='none', connectionstyle='arc3, rad = %.2f' % .75, alpha=alphas[i0], **kw) ax.add_patch(arr) # And back for i0, x in enumerate(-lspace): arr = patches.FancyArrowPatch( (xs[idx], ys[idx] + yfrom_rectif), (xs[idx + x], ys[idx + x] + yto_rectif), facecolor='none', connectionstyle='arc3, rad = %.2f' % -.75, alpha=alphas[i0], **kw) ax.add_patch(arr)
def example_elliptic(): ax.clear() ax.axis([-1.1, 2, -1.5, 1.6]) ax.axis("off") ax.add_patch(unit_circle) # the fixed point z = 0.5 + 0.2j # the elliptic transformation that rotates around z # another fixed point will be the inversion of z # about the unit circle. M = mobius.Mobius.elliptic(z, 2.*np.pi/N) # generate two orthogonal families of circles pass through z para_grid, orth_grid = mobius.generate_grids_elliptic(z, N) # get the fixed points, one of them will be z p1, p2 = M.get_fixed_points() # draw the first family for i, c in enumerate(reversed(para_grid)): col = cm.rainbow(i / N) cs = {**circstyle1, "fc": col} ls = linestyle1 mobius.plot_cline(ax, c, ls, cs) # another family for i, c in enumerate(orth_grid): cs = circstyle2 ls = {**linestyle2, "color": "m"} mobius.plot_cline(ax, c, ls, cs) if abs(p1) > 1.: p1, p2 = p2, p1 # draw fixed points ax.plot(p1.real, p1.imag, "go", markersize=6) ax.plot(p2.real, p2.imag, "bo", markersize=6) # add labels ax.text(p1.real - 0.2, p1.imag - 0.15, "$p_1$", **fontstyle) ax.text(p2.real + 0.12, p2.imag + 0.1, "$p_2$", **fontstyle) ax.text(-0.35, 0, "$M$", **fontstyle) # draw arrow start = -0.45 + 0.3j end = M(start) ax.add_patch( patches.FancyArrowPatch( (start.real, start.imag), (end.real, end.imag), connectionstyle="arc3,rad=0.2", **style ) ) fig.savefig("elliptic.svg")
def draw_axes(self, ax): path_axes = self.figure_projection.axes_path # Добавляет связанные с телом оси к рисунку: х-зеленый, y-красный, z-синий # lw - ширина линий colors = ["green", "red", "blue"] for i in range(len(path_axes)): patch = patches.FancyArrowPatch( path=path_axes[i], color=colors[i], lw=1, arrowstyle="-|>,head_length=2,head_width=2") ax.add_patch(patch)
def get_path(self, path, current): path.append( patches.FancyArrowPatch((current.x, current.y), (current.x + self.dx, current.y + self.dy), arrowstyle='-|>', edgecolor='black', facecolor='black', mutation_scale=20, lw=3.0)) current.x += self.dx current.y += self.dy return path
def _get_patch(self, s: float) -> Union[None, patches.Patch]: label = self.name colour = "black" return patches.FancyArrowPatch( (s, 1), (s, -1), arrowstyle=patches.ArrowStyle("-"), label=label, edgecolor=colour, facecolor=colour, )
def add_arrow(A, x0, y0, x1, y1): N = len(x0) i = 0 for i in range(N): #A.arrow(x0[i], y0[i], x1[i], y1[i], # head_width=0.05, head_length=0.1, fc='k', ec='k') arrow = mpatches.FancyArrowPatch((x0[i], y0[i]), ((x1[i]), (y1[i])), lw=2, mutation_scale=30, arrowstyle="-|>") A.add_patch(arrow)
def animate(t): global patch temp = random.random() ax.patches.remove(patch) patch = patches.FancyArrowPatch((9, 56), (9, 52), mutation_scale=100 * temp) ax.add_patch(patch) time_text.set_text(time_template % (t * dt)) return patch, time_text
def __init__(self, ax1, ax2, fig, text, button): self.button = button self.cid = None self.ax1 = ax1 self.ax2 = ax2 self.text = text self.return_similarity_matrix = [[], [], []] self.fig = fig self.patchl2 = patches.FancyArrowPatch( (0, 0.5), (1, 0.6), arrowstyle='<|-|>, head_length=0.1', connectionstyle="arc3, rad=-0.3", dpi_cor=2) self.patchl3 = patches.FancyArrowPatch((0.85, 0.7), (1, 0.6), arrowstyle='-', dpi_cor=2) self.patchl4 = patches.FancyArrowPatch((0.75, 0.55), (1, 0.61), arrowstyle='-', dpi_cor=2) self.patchr1 = patches.FancyArrowPatch( (1, 0.6), (0, 0.4), arrowstyle='<->', connectionstyle="arc3, rad=-0.3", dpi_cor=2) self.patchr3 = patches.FancyArrowPatch((0.01, 0.39), (0.15, 0.45), arrowstyle='-', dpi_cor=2) self.patchr4 = patches.FancyArrowPatch((0.02, 0.41), (0.08, 0.32), arrowstyle='-', dpi_cor=2) self.return_similarity_matrix = self.get_similarity_matrix()
def plot_array(result_array, ax, title=None): for i in range(5): if i == 0: plt.scatter(result_array[i][0], result_array[i][1], s=30, c="r", marker='s') elif i != 4: plt.scatter(result_array[i][0], result_array[i][1], s=30, c="b", marker='+') arrow = patches.FancyArrowPatch(result_array[i - 1], result_array[i], arrowstyle='->', linestyle='--', mutation_scale=20) ax.add_patch(arrow) else: plt.scatter(result_array[i][0], result_array[i][1], s=30, c="g", marker="o") arrow = patches.FancyArrowPatch(result_array[i - 1], result_array[i], arrowstyle='->', linestyle='--', mutation_scale=20) ax.add_patch(arrow) plt.xlim(-4.5, 4.5) plt.ylim(-4.5, 4.5) plt.xlabel("Valence", fontsize='12') plt.ylabel("Arousal", fontsize='12') if title != None: plt.title(title, fontsize='15')
def plot_histogram(list_to_be_plotted, varname, marked=None, savename=None, smoothed=None, x_min=None, x_max=None, dashed=None, solid=None): """ Plots the histogram of list_to_be_plotted, with an asterix and an arrow at marked Labels the variable axis according to varname :param list_to_be_plotted: The list to be plotted :param varname: The label for the variable-axis :param marked: Where the arrow is to appear :param savename: Filename under which the figure will be saved :param smoothed: Either none or a smoothed object :param x_min: The left end point of the range of variable-values :param x_max: The right end point of the range of variable-values :param dashed: Where to draw a vertical dashed line :param solid: Where to draw a vertical solid line :return: """ fig = plt.figure() var = pd.Series(l) var.dropna().hist(bins=30, grid=False, density=True) if smoothed is not None: x = np.linspace(x_min, x_max, 1000) plt.plot(x, smoothed(x), "-r") plt.xlabel(varname) plt.ylabel("frequency") if marked is not None: plt.plot(marked, .02, marker="*", c="r") style = "Simple,tail_width=0.5,head_width=4,head_length=8" kw = dict(arrowstyle=style, color="k") plt.text(11, .2, "critical value") arrow = mp.FancyArrowPatch(posA=[11, .2], posB=[marked + .25, 0.035], connectionstyle="arc3,rad=-.25", **kw) plt.gca().add_patch(arrow) if dashed is not None: for val in dashed: ax = plt.gca() ax.axvline(x=val, color='black', linestyle="--") if solid is not None: for val in solid: ax = plt.gca() ax.axvline(x=val, color='black', linestyle="-") plt.savefig(savename) return fig
def plot_result(ax, data): ax.plot(np.arange(1,data.shape[-1]+1), data[0], '-', color='tab:red', lw=1) ax.text(120, 0.45, 'Q-learning', color='tab:red', fontsize=14) ax.plot(np.arange(1,data.shape[-1]+1), data[1], '-', color='tab:green', lw=1) ax.text(40, 0.25, 'Double\nQ-learning', color='tab:green', fontsize=14) ax.hlines(0.05, -3, 300, linestyles='--', color='k', lw=1) ax.text(300, 0.04, 'optimal', fontsize=12, horizontalalignment='right', verticalalignment='top') ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.set_xlim((-3, 300)) ax.set_ylim((-0.02, 1)) ax.set_xticks([1, 100, 200, 300]) ax.set_yticks([0, 0.05, 0.25, 0.5, 0.75, 1]) ax.set_yticklabels([0, '5%', '25%', '50%', '75%', '100%']) ax.set_xlabel('Episodes', fontsize=14) ax.set_ylabel('% left\nactions\nfrom A', fontsize=14, rotation=0, labelpad=30) Δ = 30 ax.add_patch(patches.Rectangle((Δ+100, .8), 10, .05, fc='#aaaaaa', ec='k')) ax.plot(Δ+150, .825, 'ko', markersize=25, fillstyle='none') ax.text(Δ+150, .825, 'B', fontsize=14, horizontalalignment='center', verticalalignment='center') arrowstyle="Simple,tail_width=0.5,head_width=4,head_length=6" ax.add_artist(patches.FancyArrowPatch((Δ+145, .85), (Δ+110, .85), connectionstyle="arc3, rad=.7", arrowstyle=arrowstyle, color="k")) ax.add_artist(patches.FancyArrowPatch((Δ+143, .83), (Δ+110, .83), connectionstyle="arc3, rad=.2", arrowstyle=arrowstyle, color="k")) ax.add_artist(patches.FancyArrowPatch((Δ+145, .8), (Δ+110, .8), connectionstyle="arc3, rad=-.7", arrowstyle=arrowstyle, color="k")) ax.plot([Δ+127]*3, [.74, .845, .91], 'ko', markersize=4) ax.plot([Δ+127]*3, [.766, .792, .818], 'o', markersize=1, color='gray') ax.text(Δ+127, .92, r'$\mathcal{N}(-0.1,1)$', fontsize=12, horizontalalignment='center', verticalalignment='bottom') ax.plot(Δ+195, .825, 'ko', markersize=25, fillstyle='none') ax.text(Δ+195, .825, 'A', fontsize=14, horizontalalignment='center', verticalalignment='center') ax.arrow(Δ+204, .825, 30, 0, head_width=.01, head_length=4, length_includes_head=True, color='k') ax.plot(Δ+219, .825, 'ko', markersize=4) ax.text(Δ+219, .835, '0', fontsize=10, horizontalalignment='center', verticalalignment='bottom') ax.text(Δ+219, .81, 'right', fontsize=10, horizontalalignment='center', verticalalignment='top') ax.arrow(Δ+186, .825, -28, 0, head_width=.01, head_length=4, length_includes_head=True, color='k') ax.plot(Δ+172, .825, 'ko', markersize=4) ax.text(Δ+172, .835, '0', fontsize=10, horizontalalignment='center', verticalalignment='bottom') ax.text(Δ+172, .81, 'left', fontsize=10, horizontalalignment='center', verticalalignment='top') ax.add_patch(patches.Rectangle((Δ+235, .8), 10, .05, fc='#aaaaaa', ec='k'))
def test_arrow_styles(): styles = mpatches.ArrowStyle.get_styles() n = len(styles) fig, ax = plt.subplots(figsize=(6, 10)) ax.set_xlim(0, 1) ax.set_ylim(-1, n) for i, stylename in enumerate(sorted(styles)): patch = mpatches.FancyArrowPatch((0.1, i), (0.8, i), arrowstyle=stylename, mutation_scale=25) ax.add_patch(patch)
def draw_single_arrow(self, tail_coord, head_coord, arrow_size): x_head, y_head = head_coord x_tail, y_tail = tail_coord ax = self.fig.add_axes([0, 0, 1, 1]) ax.patch.set_facecolor('None') arrow = mpatches.FancyArrowPatch((x_tail, y_tail), (x_head, y_head), mutation_scale=arrow_size, arrowstyle="simple", edgecolor=None, color=self.color_transfer( (66, 66, 66))) ax.add_patch(arrow) self.hide_axis(ax)
def plotEffectUncertaintiesPLLA(configuration, graphName): # dataPacketLoss = [ao.pl for ao in configuration[0:60]] # minPL, maxPL = min(dataPacketLoss), max(dataPacketLoss) # dataEnergyConsumption = [ao.ec for ao in configuration[0:60]] # minEC, maxEC = min(dataEnergyConsumption), max(dataEnergyConsumption) mlp.rcParams['font.size'] = 18 # Plot 10 data points per graph for i in range(1): plt.figure(figsize=(10,10)) ax = plt.subplot(1, 1, 1) # plot the arrows between the points for j in range(i * 10, (i * 10) + 9): first = configuration[j] second = configuration[j+1] disX = abs(first.pl - second.pl) disY = abs(first.la - second.la) dis = (disX**2 + disY**2)**.5 if dis != 0: adjX = (disX / dis) * 0.025 * (1 if first.pl < second.pl else -1) adjY = (disY / dis) * 0.009 * (1 if first.la < second.la else -1) else: adjX = 0 adjY = 0 ax.add_patch(mpatches.FancyArrowPatch( (first.pl + adjX, first.la + adjY), (second.pl - adjX, second.la - adjY), mutation_scale=20) ) # plot the points for j in range(i * 10, (i + 1) * 10): if j == i*10: plt.scatter(configuration[j].pl, configuration[j].la, color='green', s=200, marker='*', edgecolors='black') else: plt.scatter(configuration[j].pl, configuration[j].la, color='green', s=150, marker='o', edgecolors='black') plt.xlabel('Packet loss (%)') plt.ylabel('Latency (%)') # x1, x2, y1, y2 = plt.axis() plt.plot([10,10], [0,8], color='red') plt.plot([7,12], [5,5], color='red') plt.axis([7, 12, 0, 8]) outputDir = createOrGetDir('EffectUncertaintiesPLLA') plt.savefig(os.path.join(outputDir, f'EffectUncertainties_{graphName}_Cycles[{(i*10)+1}-{((i+1)*10)}].pdf'), bbox_inches='tight') plt.close()
def plot_message(message, self_message=False): x_loc = obj_x_locations_map[message.send_coordinates.sim_obj_id] y_loc = message.send_coordinates.time x_end = obj_x_locations_map[message.receive_coordinates.sim_obj_id] y_end = message.receive_coordinates.time connectionstyle = None kw_args['color'] = self.plot_params['msg_to_other_color'] if self_message: connectionstyle = f"arc3,rad={self.plot_params['msg_self_arrow_radius']}" kw_args['color'] = self.plot_params['msg_to_self_color'] arrow = patches.FancyArrowPatch((x_loc, y_loc), (x_end, y_end), connectionstyle=connectionstyle, **kw_args) plt.gca().add_patch(arrow)
def plot_feature(self, ax, feature, level, linewidth=1.0): """Create an Arrow Matplotlib patch with the feature's coordinates. The Arrow points in the direction of the feature's strand. If the feature has no direction (strand==0), the returned patch will simply be a rectangle. The x-coordinates of the patch are determined by the feature's `start` and `end` while the y-coordinates are determined by the `level` """ x1, x2 = feature.start, feature.end if feature.open_left: x1 -= 1 if feature.open_right: x2 += 1 if feature.strand == -1: x1, x2 = x2, x1 x1, x2 = x1 - 0.5, x2 - 0.5 is_undirected = feature.strand not in (-1, 1) head_is_cut = (feature.strand == 1 and feature.open_right) or (feature.strand == -1 and feature.open_left) if is_undirected or head_is_cut: head_length = 0.001 else: width_pixel = self._get_ax_width(ax, unit="pixel") head_length = (0.5 * width_pixel * feature.length / self.sequence_length) head_length = min(head_length, 0.6 * feature.thickness) arrowstyle = mpatches.ArrowStyle.Simple( head_width=feature.thickness, tail_width=feature.thickness, head_length=head_length, ) y = self.feature_level_height * level patch = mpatches.FancyArrowPatch( [x1, y], [x2, y], shrinkA=0.0, shrinkB=0.0, arrowstyle=arrowstyle, facecolor=feature.color, zorder=0, edgecolor=feature.linecolor, linewidth=feature.linewidth, ) ax.add_patch(patch) return patch