def poly_draw(final_polys, canvas=[], fig=[], ax=[], mirror_ax=None, origin=np.zeros(2), cmap=cm.rainbow): from shapely.affinity import scale, translate if not fig: fig, ax = plt.subplots() elecs = list(final_polys.keys()) for num, elec in final_polys.items(): for poly in elec: if poly: if canvas: poly = poly.difference( poly.difference(gem_poly().get_poly( 'box', np.array([0, 0, canvas[0], canvas[1]])))) if mirror_ax: if mirror_ax.lower() == 'y': Q1 = scale(poly, yfact=-1, origin=(0, 0)) elif mirror_ax.lower() == 'x': Q1 = scale(poly, xfact=-1, origin=(0, 0)) Q1 = translate(Q1, -origin[0], -origin[1]) tpatch = PolygonPatch(Q1) tpatch.set_color(cmap(num / max(elecs))) tpatch.set_linewidth(0) ax.add_patch(tpatch) poly = translate(poly, -origin[0], -origin[1]) patch = PolygonPatch(poly) patch.set_color(cmap(num / max(elecs))) patch.set_linewidth(0) ax.add_patch(patch) ax.autoscale(enable=True) ax.set_aspect('equal') return (fig, ax)
hm_polyg, color_ids = dc.hm2polygons(HM) fig = plt.figure() ax = plt.subplot(111) clrs = cm.Greens(range(256)) nd = max(color_ids) + 1 clrs = dc.downsample_matrix(clrs, int(np.floor(256 / nd))) plt.set_cmap(cm.Greens) i = 0 for pg in hm_polyg: if not (pg == []): p = PolygonPatch(pg, ec=clrs[color_ids[i] - 1, :], fc=clrs[color_ids[i] - 1, :]) p.set_linewidth(3) ax.add_patch(p) i += 1 plt.axis('equal') plt.xticks([]) plt.yticks([]) plt.xlim((0, ny)) plt.ylim((0, nx)) axc = fig.add_axes([0.8, 0.15, 0.03, 0.18]) cmap = mpl.cm.Greens norm = mpl.colors.Normalize(vmin=1, vmax=len(mice)) cb = mpl.colorbar.ColorbarBase(axc, cmap=cmap, norm=norm, orientation='vertical')