def _add_inner_title(ax, title, loc, size=None, **kwargs): if size is None: size = dict(size=pp.rcParams['legend.fontsize']) at = AnchoredText(title, loc=loc, prop=size, pad=0., borderpad=0.5, frameon=False, **kwargs) at.set_zorder(200) ax.add_artist(at) at.txt._text.set_path_effects([withStroke(foreground="w", linewidth=3)]) return at
def _add_inner_title(self, ax, title, loc, size=None, **kwargs): if size is None: size = dict(size=pp.rcParams['legend.fontsize']) at = AnchoredText( title, loc=loc, prop=size, pad=0., borderpad=0.5, frameon=False, **kwargs ) at.set_zorder(200) ax.add_artist(at) at.txt._text.set_path_effects( [withStroke(foreground="w", linewidth=3)] ) return at
def add_inner_title(ax, title, loc, size=None, **kwargs): from matplotlib.offsetbox import AnchoredText from matplotlib.patheffects import withStroke if size is None: size = dict(size=pp.rcParams["legend.fontsize"]) at = AnchoredText(title, loc=loc, prop=size, pad=0.0, borderpad=0.5, frameon=False, **kwargs) at.set_zorder(200) ax.add_artist(at) at.txt._text.set_path_effects([withStroke(foreground="w", linewidth=3)]) return at
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # if "main" axes if not kwargs.get("sharex"): text = AnchoredText("PRELIMINARY", loc="center", frameon=False, borderpad=0, prop=dict(alpha=0.15, fontsize=50, rotation=30, color="black")) text.set_path_effects( [Stroke(linewidth=3, foreground="white"), Normal()]) text.set_zorder(1000) self.add_artist(text)
def writeSubplotLabel(ax, loc, txt, frameon=True, alpha=1.0, fontsize=FS, pad=0.005, ma='none', bbox=None, zorder=None): at = AnchoredText(txt, loc=loc, prop=dict(size=fontsize), frameon=frameon, bbox_to_anchor=bbox, bbox_transform=ax.transAxes) at.patch.set_linewidth(0.7) if zorder is not None: at.set_zorder(zorder) ax.add_artist(at)
def plot_topology(self, circuits, equipments_multipoint, partition_by_station_dict, cities, destdir): (ymin, xmin, ymax, xmax) = equipments_multipoint.buffer(0.2).bounds sidebar_width = (xmax - xmin) * 0.4 sidebar_height = ymax - ymin self.root.info('Plotting Voltages %s' % str((ymin, xmin, ymax, xmax))) ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_extent([xmin, xmax + sidebar_width, ymin, ymax]) for circuit in circuits: plt.plot(circuit.members[0].lon, circuit.members[0].lat, marker='s', markerfacecolor='black', linestyle="None", markersize=1, zorder=10, transform=ccrs.PlateCarree()) plt.plot(circuit.members[-1].lon, circuit.members[-1].lat, marker='s', markerfacecolor='black', linestyle="None", markersize=1, zorder=10, transform=ccrs.PlateCarree()) # ax.annotate(circuit.members[0].id, (circuit.members[0].lon, circuit.members[0].lat)) # ax.annotate(circuit.members[-1].id, (circuit.members[-1].lon, circuit.members[-1].lat)) for line in circuit.members[1:-1]: x, y = line.geom.xy plt.plot(x, y, color=self.color_dict[line.voltage.split(';')[0]], alpha=1, linewidth=self.thickness_dict[line.voltage.split(';')[0]], solid_capstyle='round', zorder=self.zorder_dict[line.voltage.split(';')[0]], transform=ccrs.PlateCarree()) if cities: for city in cities: if xmax > city.lon > xmin and ymax > city.lat > ymin: plt.plot(city.lon, city.lat, marker='s', markerfacecolor='#ff0000', linestyle="None", markersize=log(city.population, 10), zorder=1.5) if city.population >= 200000 and 'DEUTSCHLAND' not in city.name: label = city.name ax.annotate(label, (city.lon, city.lat)) # sidebar ax.add_patch(patches.Rectangle((xmax, ymin), sidebar_width, sidebar_height, facecolor="white", zorder=10)) im = image.imread('../util/logo2.png') ax.imshow(im, aspect='auto', extent=( xmax + sidebar_width / 4, xmax + 3 * sidebar_width / 4, ymax - sidebar_height / 3, ymax - sidebar_height / 2), zorder=11) # noinspection PyTypeChecker text = AnchoredText('(c) OpenGridMap', loc=1, prop={'size': 12}, frameon=True, borderpad=0.8) text.set_zorder(11) ax.add_artist(text) plt.plot([], [], marker='s', markerfacecolor='black', linestyle="None", markersize=1, zorder=11, label='station') for voltage in self.color_dict.keys(): label = str(voltage) + 'V' plt.plot([], [], color=self.color_dict[voltage], lw=self.thickness_dict[voltage], zorder=11, label=label) l = plt.legend(numpoints=1, loc=4) l.set_zorder(11) plt.savefig(destdir + '/topology.png', bbox_inches='tight', pad_inches=0, dpi=600) ax.stock_img() plt.savefig(destdir + '/topology_geographical.png', bbox_inches='tight', pad_inches=0, dpi=600) countries = cfeature.NaturalEarthFeature( category='cultural', name='admin_0_countries', scale='10m', facecolor='none') states_provinces = cfeature.NaturalEarthFeature( category='cultural', name='admin_1_states_provinces_shp', scale='10m', facecolor='none') ax.add_feature(states_provinces, edgecolor='#ffffff', linewidth=0.3) ax.add_feature(countries, edgecolor='#333333', linewidth=0.5) kw = dict(resolution='50m', category='cultural', name='populated_places_simple') places_shp = shpreader.natural_earth(**kw) shp = shpreader.Reader(places_shp) for record, place in zip(shp.records(), shp.geometries()): if xmax > place.x > xmin and ymax > place.y > ymin: name = record.attributes['name'].decode('latin-1') plt.plot(place.x, place.y, marker='o', markerfacecolor='#ff0000', linestyle="None", markersize=2, zorder=11) ax.annotate(name, (place.x, place.y), fontsize=4) plt.savefig(destdir + '/topology_administrative.png', bbox_inches='tight', pad_inches=0, dpi=600) # Voronoi partitions if partition_by_station_dict: for station in partition_by_station_dict.keys(): partition_polygon = partition_by_station_dict[station] if hasattr(partition_polygon, 'geoms'): for polygon in partition_polygon: Plotter.plot_polygon(polygon, '#888888', zorder=2) else: Plotter.plot_polygon(partition_polygon, '#888888', zorder=2) plt.plot([], [], color='#888888', lw=2, zorder=5, label='Voronoi partitions') plt.savefig(destdir + '/topology_voronoi.png', bbox_inches='tight', pad_inches=0, dpi=600) plt.clf() plt.close()
def plot_topology(self, circuits, equipments_multipoint, partition_by_station_dict, cities, destdir): (ymin, xmin, ymax, xmax) = equipments_multipoint.buffer(0.2).bounds sidebar_width = (xmax - xmin) * 0.4 sidebar_height = ymax - ymin self.root.info('Plotting Voltages %s' % str((ymin, xmin, ymax, xmax))) ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_extent([xmin, xmax + sidebar_width, ymin, ymax]) for circuit in circuits: plt.plot(circuit.members[0].lon, circuit.members[0].lat, marker='s', markerfacecolor='black', linestyle="None", markersize=1, zorder=10, transform=ccrs.PlateCarree()) plt.plot(circuit.members[-1].lon, circuit.members[-1].lat, marker='s', markerfacecolor='black', linestyle="None", markersize=1, zorder=10, transform=ccrs.PlateCarree()) # ax.annotate(circuit.members[0].id, (circuit.members[0].lon, circuit.members[0].lat)) # ax.annotate(circuit.members[-1].id, (circuit.members[-1].lon, circuit.members[-1].lat)) for line in circuit.members[1:-1]: x, y = line.geom.xy plt.plot(x, y, color=self.color_dict[line.voltage.split(';')[0]], alpha=1, linewidth=self.thickness_dict[line.voltage.split(';')[0]], solid_capstyle='round', zorder=self.zorder_dict[line.voltage.split(';')[0]], transform=ccrs.PlateCarree()) if cities: for city in cities: if xmax > city.lon > xmin and ymax > city.lat > ymin: plt.plot(city.lon, city.lat, marker='s', markerfacecolor='#ff0000', linestyle="None", markersize=log(city.population, 10), zorder=1.5) if city.population >= 200000 and 'DEUTSCHLAND' not in city.name: label = city.name ax.annotate(label, (city.lon, city.lat)) # sidebar ax.add_patch(patches.Rectangle((xmax, ymin), sidebar_width, sidebar_height, facecolor="white", zorder=10)) im = image.imread('../util/logo2.png') ax.imshow(im, aspect='auto', extent=( xmax + sidebar_width / 4, xmax + 3 * sidebar_width / 4, ymax - sidebar_height / 3, ymax - sidebar_height / 2), zorder=11) text = AnchoredText('(c) OpenGridMap', loc=1, prop={'size': 12}, frameon=True, borderpad=0.8) text.set_zorder(11) ax.add_artist(text) plt.plot([], [], marker='s', markerfacecolor='black', linestyle="None", markersize=1, zorder=11, label='station') for voltage in self.color_dict.keys(): label = str(voltage) + 'V' plt.plot([], [], color=self.color_dict[voltage], lw=self.thickness_dict[voltage], zorder=11, label=label) l = plt.legend(numpoints=1, loc=4) l.set_zorder(11) plt.savefig(destdir + '/topology.png', bbox_inches='tight', pad_inches=0, dpi=600) ax.stock_img() plt.savefig(destdir + '/topology_geographical.png', bbox_inches='tight', pad_inches=0, dpi=600) countries = cfeature.NaturalEarthFeature( category='cultural', name='admin_0_countries', scale='10m', facecolor='none') states_provinces = cfeature.NaturalEarthFeature( category='cultural', name='admin_1_states_provinces_shp', scale='10m', facecolor='none') ax.add_feature(states_provinces, edgecolor='#ffffff', linewidth=0.3) ax.add_feature(countries, edgecolor='#333333', linewidth=0.5) kw = dict(resolution='50m', category='cultural', name='populated_places_simple') places_shp = shpreader.natural_earth(**kw) shp = shpreader.Reader(places_shp) for record, place in zip(shp.records(), shp.geometries()): if xmax > place.x > xmin and ymax > place.y > ymin: name = record.attributes['name'].decode('latin-1') plt.plot(place.x, place.y, marker='o', markerfacecolor='#ff0000', linestyle="None", markersize=2, zorder=11) ax.annotate(name, (place.x, place.y), fontsize=4) plt.savefig(destdir + '/topology_administrative.png', bbox_inches='tight', pad_inches=0, dpi=600) # Voronoi partitions if partition_by_station_dict: for station in partition_by_station_dict.keys(): partition_polygon = partition_by_station_dict[station] if hasattr(partition_polygon, 'geoms'): for polygon in partition_polygon: Plotter.plot_polygon(polygon, '#888888', zorder=2) else: Plotter.plot_polygon(partition_polygon, '#888888', zorder=2) plt.plot([], [], color='#888888', lw=2, zorder=5, label='Voronoi partitions') plt.savefig(destdir + '/topology_voronoi.png', bbox_inches='tight', pad_inches=0, dpi=600) plt.clf() plt.close()