def _draw_settlement_zones(building_zones: List[m.BuildingZone], ax: maxs.Axes) -> None: for building_zone in building_zones: colour = 'grey' if building_zone.type_ is enu.BuildingZoneType.farmyard: colour = 'brown' _add_patch_for_building_zone(building_zone, colour, colour, ax) for block in building_zone.linked_city_blocks: if block.settlement_type is enu.SettlementType.centre: colour = 'blue' elif block.settlement_type is enu.SettlementType.block: colour = 'green' elif block.settlement_type is enu.SettlementType.dense: colour = 'magenta' elif block.settlement_type is enu.SettlementType.periphery: colour = 'yellow' patch = PolygonPatch(block.geometry, facecolor=colour, edgecolor=colour) if block.settlement_type_changed: patch.set_hatch('/') ax.add_patch(patch)
def plot_counties( ax, counties, values=None, edgecolors=None, contourcolor="white", hatch_surround=None, xlim=None, ylim=None, background=True, xticks=True, yticks=True, grid=True, frame=True, xlabel="Longitude [in dec. degrees]", ylabel="Latitude [in dec. degrees]", lw=1): polygons = [r["shape"] for r in counties.values()] # extend german borders :S and then shrink them again after unifying # gets rid of many holes at the county boundaries contour = cascaded_union([pol.buffer(0.01) for pol in polygons]).buffer(-0.01) xmin, ymin, xmax, ymax = contour.bounds if xlim is None: xlim = [xmin, xmax] if ylim is None: ylim = [ymin, ymax] surround = PolygonPatch(Polygon([(xlim[0], ylim[0]), (xlim[0], ylim[1]), ( xlim[1], ylim[1]), (xlim[1], ylim[0])]).difference(contour)) contour = PolygonPatch(contour, lw=lw) pc = PatchCollection([PolygonPatch(p, lw=lw) for p in polygons], cmap=matplotlib.cm.magma, alpha=1.0) if values is not None: if isinstance(values, (dict, OrderedDict)): values = np.array([values.setdefault(r, np.nan) for r in counties.keys()]) elif isinstance(values, str): values = np.array([r.setdefault(values, np.nan) for r in counties.values()]) else: assert np.size(values) == len(counties), "Number of values ({}) doesn't match number of counties ({})!".format( np.size(values), len(counties)) pc.set_clim(0, 10) nans = np.isnan(values) values[nans] = 0 values = np.ma.MaskedArray(values, mask=nans) pc.set(array=values, cmap='magma') else: pc.set_facecolors("none") if edgecolors is not None: if isinstance(edgecolors, (dict, OrderedDict)): edgecolors = np.array([edgecolors.setdefault(r, "none") for r in counties.keys()]) elif isinstance(edgecolors, str): edgecolors = np.array([r.setdefault(edgecolors, "none") for r in counties.values()]) pc.set_edgecolors(edgecolors) else: pc.set_edgecolors("none") if hatch_surround is not None: surround.set_hatch(hatch_surround) surround.set_facecolor("none") ax.add_patch(surround) cb = plt.colorbar(pc, shrink=0.6) cb.set_ticks([0,5,10]) #cb.set_yticks([0.00004]) ax.add_collection(pc) if contourcolor is not None: contour.set_edgecolor(contourcolor) contour.set_facecolor("none") ax.add_patch(contour) if isinstance(background, bool): ax.patch.set_visible(background) else: ax.patch.set_color(background) ax.grid(grid) ax.set_frame_on(frame) ax.set_xlim(*xlim) ax.set_ylim(*ylim) ax.set_aspect(1.43) if xlabel: ax.set_xlabel(xlabel, fontsize=14) if ylabel: ax.set_ylabel(ylabel, fontsize=14) ax.tick_params(axis="x", which="both", bottom=xticks, labelbottom=xticks) ax.tick_params(axis="y", which="both", left=yticks, labelleft=yticks) #plt.colorbar() return pc, contour, surround