def draw_motion_state(ms, width, length, id, patchesDict, textDict, axes, color=None): if id not in patchesDict: polygon = polygon_xy_from_motionstate(ms, width, length) rect = matplotlib.patches.Polygon(polygon, closed=True, zorder=20, facecolor=color, edgecolor='black') patchesDict[id] = rect axes.add_patch(rect) textDict[id] = axes.text(ms.x, ms.y + 2, str(id), horizontalalignment='center', zorder=30) else: patchesDict[id].set_xy(polygon_xy_from_motionstate(ms, width, length)) textDict[id].set_position((ms.x, ms.y + 2))
def __init__(self, axes, origin=None, scale=1, add_coords=None, style=None, convert_2d=None, label_vertices=False): """Construct an instance.""" self._sequence = Sequence() if convert_2d is None: self._convert_2d = self._first_two_coordinates else: self._convert_2d = convert_2d self._square = utility.square(origin, scale, add_coords=add_coords) if style: self._patch = patches.Polygon(self._square[:, :2], **style) else: self._patch = patches.Polygon(self._square[:, :2]) axes.add_patch(self._patch) self._labels = [] if label_vertices: for (x, y), label in zip(self._patch.get_xy(), ["BL", "TL", "TR", "BR"]): text = axes.text(x, y, label) text.set_clip_on(True) self._labels.append(text) self._update_index = 0
def show_detect_result(imgs_arr=[], all_boxes=[]): trans_func = transforms.ToPILImage() imgs_one_line = int(len(imgs_arr) / 2 + (len(imgs_arr) % 2)) for idx, img in enumerate(imgs_arr): # img_plt = trans_func(img).convert('RGB') axes = plt.subplot(2, imgs_one_line, (idx + 1)) i = 0 objs = all_boxes[idx] print('len(objs): ', len(objs)) for obj_class in objs: # print('item[0]: ', int(item[0].item())) for item in obj_class: print('item.shape: ', item.shape) name = labelmap[int(item[0])] score = item[1] xmin = int(item[2]) ymin = int(item[3]) xmax = int(item[4]) ymax = int(item[5] ) # print('name: ', name) # print('(xmin, ymin, xmax, ymax): ', xmin, ymin, xmax, ymax) i += 1 i %= len(color_list) rect = patches.Rectangle((xmin, ymin), (xmax - xmin), (ymax - ymin), linewidth=2, edgecolor=color_list[i], fill=False) if args.score == True: axes.text(rect.xy[0], rect.xy[1], str(score), va='center', ha='center', color=color_list[i], bbox=dict(facecolor='w')) if args.bbox == True: axes.add_patch(rect) if args.label == True: axes.text(rect.xy[0], rect.xy[1], name, va='center', ha='center', color='k', bbox=dict(facecolor='w')) plt.imshow(img) plt.axis('off') plt.ioff() viz = Visdom(env='ssd_obj_detect') viz.matplot(plt)
def bar_label(ax, rects, semilog): (y_bottom, y_top) = ax.get_ylim() y_height = y_top - y_bottom for rect in rects: height = rect.get_height() p_height = (height / y_height) # just put all labels above bars if semilog: if p_height > 1.95: label_position = height * (0.95) else: label_position = height * (1.05) else: if p_height > 1.95: label_position = height - (y_height * 0.05) else: label_position = height + (y_height * 0.01) ax.text(rect.get_x() + rect.get_width() / 2., label_position, '%5.1f' % height, ha='center', va='bottom')
#User input yval = int(input()) mycolor = [] for ulim, lowlim in zip(upper_limit, lower_limit): if ulim < yval: mycolor.append('Darkblue') elif ulim >= yval and lowlim <= yval: mycolor.append('Ghostwhite') else: mycolor.append('Darkred') a11 = (moe_a11,moe_b11,moe_c11,moe_d11) plt.bar(x1, y1, width = 0.9, tick_label = ['1992', '1993','1994','1995'], color = mycolor, yerr = a11, capsize = 8) plt.axis([1991.5,1996,1000,52500]) plt.xlabel('Year') plt.axhline(y = yval, alpha = 0.8, label = yval, color = 'Gray') ax = plt.gca() plt.legend(['Value of Interest']) ax.text(1991.5,yval,yval, color = 'black') # In[ ]:
def labeling(rects): for rect in rects: height = rect.get_height() ax.text(rect.get_x() + rect.get_width()/2., 1.02*height,'%f' % float(height), ha='center', va='bottom')
for j in range(0, 3): ax = axes[i, j] ax.minorticks_on() ax.yaxis.set_major_locator(ticker.MultipleLocator(10)) ax.yaxis.set_minor_locator(ticker.MultipleLocator(2)) ax.xaxis.set_major_locator(ticker.MultipleLocator(10)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(2)) ax.tick_params(axis='both', which='both', direction='in', right=True, top=True) ax.text(0.1, 0.9, "{}".format(labels[i][j]), fontsize=18, ha="center", va="center", transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.75, edgecolor='.75')) #setting the phase plots if ax == axes[1, 0] or ax == axes[2, 0] or ax == axes[2, 1]: im = ax.imshow(frb[fields[i][j]].d, origin='lower', extent=[ ds.domain_left_edge[1].value, ds.domain_right_edge[1].value, ds.domain_left_edge[2].value, ds.domain_right_edge[2].value ], vmin=-180, vmax=180,