def as_mpl_artists(shape_list,<EOL>properties_func=None,<EOL>text_offset=<NUM_LIT>, origin=<NUM_LIT:1>):
patch_list = []<EOL>artist_list = []<EOL>if properties_func is None:<EOL><INDENT>properties_func = properties_func_default<EOL><DEDENT>saved_attrs = None<EOL>for shape in shape_list:<EOL><INDENT>patches = []<EOL>if saved_attrs is None:<EOL><INDENT>_attrs = [], {}<EOL><DEDENT>else:<EOL><INDENT>_attrs = copy.copy(saved_attrs[<NUM_LIT:0>]), copy.copy(saved_attrs[<NUM_LIT:1>])<EOL><DEDENT>kwargs = properties_func(shape, _attrs)<EOL>if shape.name == "<STR_LIT>":<EOL><INDENT>saved_attrs = shape.attr<EOL>continue<EOL><DEDENT>if saved_attrs is None and shape.continued:<EOL><INDENT>saved_attrs = shape.attr<EOL><DEDENT>if not shape.continued:<EOL><INDENT>saved_attrs = None<EOL><DEDENT>txt = shape.attr[<NUM_LIT:1>].get("<STR_LIT:text>")<EOL>if shape.name == "<STR_LIT>":<EOL><INDENT>xy = np.array(shape.coord_list)<EOL>xy.shape = -<NUM_LIT:1>, <NUM_LIT:2><EOL>patches = [mpatches.Polygon(xy - origin, closed=True, **kwargs)]<EOL><DEDENT>elif shape.name == "<STR_LIT>" or shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, w, h, rot = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>_box = np.array([[-w / <NUM_LIT>, -h / <NUM_LIT>],<EOL>[-w / <NUM_LIT>, h / <NUM_LIT>],<EOL>[w / <NUM_LIT>, h / <NUM_LIT>],<EOL>[w / <NUM_LIT>, -h / <NUM_LIT>]])<EOL>box = _box + [xc, yc]<EOL>rotbox = rotated_polygon(box, xc, yc, rot)<EOL>patches = [mpatches.Polygon(rotbox, closed=True, **kwargs)]<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc = shape.coord_list[:<NUM_LIT:2>]<EOL>xc, yc = xc - origin, yc - origin<EOL>angle = shape.coord_list[-<NUM_LIT:1>]<EOL>maj_list, min_list = shape.coord_list[<NUM_LIT:2>:-<NUM_LIT:1>:<NUM_LIT:2>], shape.coord_list[<NUM_LIT:3>:-<NUM_LIT:1>:<NUM_LIT:2>]<EOL>patches = [mpatches.Ellipse((xc, yc), <NUM_LIT:2> * maj, <NUM_LIT:2> * min,<EOL>angle=angle, **kwargs)<EOL>for maj, min in zip(maj_list, min_list)]<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc = shape.coord_list[:<NUM_LIT:2>]<EOL>xc, yc = xc - origin, yc - origin<EOL>r_list = shape.coord_list[<NUM_LIT:2>:]<EOL>patches = [mpatches.Ellipse((xc, yc), <NUM_LIT:2> * r, <NUM_LIT:2> * r, **kwargs) for r in r_list]<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, major = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>patches = [mpatches.Ellipse((xc, yc), <NUM_LIT:2> * major, <NUM_LIT:2> * major, angle=<NUM_LIT:0>, **kwargs)]<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, a1, a2, an, r1, r2, rn = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>patches = [mpatches.Arc((xc, yc), rr * <NUM_LIT:2>, rr * <NUM_LIT:2>, angle=<NUM_LIT:0>,<EOL>theta1=a1, theta2=a2, **kwargs)<EOL>for rr in np.linspace(r1, r2, rn + <NUM_LIT:1>)]<EOL>for aa in np.linspace(a1, a2, an + <NUM_LIT:1>):<EOL><INDENT>xx = np.array([r1, r2]) * np.cos(aa / <NUM_LIT> * np.pi) + xc<EOL>yy = np.array([r1, r2]) * np.sin(aa / <NUM_LIT> * np.pi) + yc<EOL>p = Path(np.transpose([xx, yy]))<EOL>patches.append(mpatches.PathPatch(p, **kwargs))<EOL><DEDENT><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, r1, r2, a1, a2 = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>patches = [mpatches.Arc((xc, yc), rr * <NUM_LIT:2>, rr * <NUM_LIT:2>, angle=<NUM_LIT:0>,<EOL>theta1=a1, theta2=a2, **kwargs)<EOL>for rr in [r1, r2]]<EOL>for aa in [a1, a2]:<EOL><INDENT>xx = np.array([r1, r2]) * np.cos(aa / <NUM_LIT> * np.pi) + xc<EOL>yy = np.array([r1, r2]) * np.sin(aa / <NUM_LIT> * np.pi) + yc<EOL>p = Path(np.transpose([xx, yy]))<EOL>patches.append(mpatches.PathPatch(p, **kwargs))<EOL><DEDENT><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, a1, a2, an, r11, r12, r21, r22, rn, angle = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>x1, y1 = cos(a1 / <NUM_LIT> * pi), sin(a1 / <NUM_LIT> * pi) * r11 / r12<EOL>x2, y2 = cos(a2 / <NUM_LIT> * pi), sin(a2 / <NUM_LIT> * pi) * r11 / r12<EOL>a1, a2 = atan2(y1, x1) / pi * <NUM_LIT>, atan2(y2, x2) / pi * <NUM_LIT><EOL>patches = [mpatches.Arc((xc, yc), rr1 * <NUM_LIT:2>, rr2 * <NUM_LIT:2>,<EOL>angle=angle, theta1=a1, theta2=a2,<EOL>**kwargs)<EOL>for rr1, rr2 in zip(np.linspace(r11, r21, rn + <NUM_LIT:1>),<EOL>np.linspace(r12, r22, rn + <NUM_LIT:1>))]<EOL>for aa in np.linspace(a1, a2, an + <NUM_LIT:1>):<EOL><INDENT>xx = np.array([r11, r21]) * np.cos(aa / <NUM_LIT> * np.pi)<EOL>yy = np.array([r11, r21]) * np.sin(aa / <NUM_LIT> * np.pi)<EOL>p = Path(np.transpose([xx, yy]))<EOL>tr = Affine2D().scale(<NUM_LIT:1>, r12 / r11).rotate_deg(angle).translate(xc, yc)<EOL>p2 = tr.transform_path(p)<EOL>patches.append(mpatches.PathPatch(p2, **kwargs))<EOL><DEDENT><DEDENT>elif shape.name == "<STR_LIT:text>":<EOL><INDENT>xc, yc = shape.coord_list[:<NUM_LIT:2>]<EOL>xc, yc = xc - origin, yc - origin<EOL>if txt:<EOL><INDENT>_t = _get_text(txt, xc, yc, <NUM_LIT:0>, <NUM_LIT:0>, **kwargs)<EOL>artist_list.append(_t)<EOL><DEDENT><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc = shape.coord_list[:<NUM_LIT:2>]<EOL>xc, yc = xc - origin, yc - origin<EOL>artist_list.append(Line2D([xc], [yc],<EOL>**kwargs))<EOL>if txt:<EOL><INDENT>textshape = copy.copy(shape)<EOL>textshape.name = "<STR_LIT:text>"<EOL>textkwargs = properties_func(textshape, _attrs)<EOL>_t = _get_text(txt, xc, yc, <NUM_LIT:0>, text_offset,<EOL>va="<STR_LIT>",<EOL>**textkwargs)<EOL>artist_list.append(_t)<EOL><DEDENT><DEDENT>elif shape.name in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>if shape.name == "<STR_LIT>":<EOL><INDENT>x1, y1, x2, y2 = shape.coord_list[:<NUM_LIT:4>]<EOL>x1, y1, x2, y2 = x1 - origin, y1 - origin, x2 - origin, y2 - origin<EOL>a1, a2 = shape.attr[<NUM_LIT:1>].get("<STR_LIT>", "<STR_LIT>").strip().split()[:<NUM_LIT:2>]<EOL>arrowstyle = "<STR_LIT:->"<EOL>if int(a1):<EOL><INDENT>arrowstyle = "<STR_LIT:<>" + arrowstyle<EOL><DEDENT>if int(a2):<EOL><INDENT>arrowstyle = arrowstyle + "<STR_LIT:>>"<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>x1, y1, l, a = shape.coord_list[:<NUM_LIT:4>]<EOL>x1, y1 = x1 - origin, y1 - origin<EOL>x2, y2 = x1 + l * np.cos(a / <NUM_LIT> * np.pi), y1 + l * np.sin(a / <NUM_LIT> * np.pi)<EOL>v1 = int(shape.attr[<NUM_LIT:1>].get("<STR_LIT>", "<STR_LIT:0>").strip())<EOL>if v1:<EOL><INDENT>arrowstyle = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>arrowstyle = "<STR_LIT:->"<EOL><DEDENT><DEDENT>patches = [mpatches.FancyArrowPatch(posA=(x1, y1),<EOL>posB=(x2, y2),<EOL>arrowstyle=arrowstyle,<EOL>arrow_transmuter=None,<EOL>connectionstyle="<STR_LIT>",<EOL>patchA=None, patchB=None,<EOL>shrinkA=<NUM_LIT:0>, shrinkB=<NUM_LIT:0>,<EOL>connector=None,<EOL>**kwargs)]<EOL><DEDENT>else:<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>".format(shape.name))<EOL><DEDENT>patch_list.extend(patches)<EOL>if txt and patches:<EOL><INDENT>textshape = copy.copy(shape)<EOL>textshape.name = "<STR_LIT:text>"<EOL>textkwargs = properties_func(textshape, _attrs)<EOL>_bb = [p.get_window_extent() for p in patches]<EOL>for p in patches:<EOL><INDENT>p._transformSet = False<EOL><DEDENT>_bbox = Bbox.union(_bb)<EOL>x0, y0, x1, y1 = _bbox.extents<EOL>xc = <NUM_LIT> * (x0 + x1)<EOL>_t = _get_text(txt, xc, y1, <NUM_LIT:0>, text_offset,<EOL>va="<STR_LIT>",<EOL>**textkwargs)<EOL>artist_list.append(_t)<EOL><DEDENT><DEDENT>return patch_list, artist_list<EOL>
Converts a region list to a list of patches and a list of artists.


Optional Keywords:
[ text_offset ] - If there is text associated with the regions, add
some vertical offset (in pixels) to the text so that it doesn't overlap
with the regions.

Often, the regions files implicitly assume the lower-left corner
of the image as a coordinate (1,1). However, the python convetion
is that the array index starts from 0. By default (origin = 1),
coordinates of the returned mpl artists have coordinate shifted by
(1, 1). If you do not want this shift, set origin=0.