def component_plot(n, linewidth_factor=5e3, gen_size_factor=5e4, sus_size_factor=1e4, carrier_colors=None, carrier_names=None, figsize=(10, 5), boundaries=None, **kwargs): """ Plot a pypsa.Network generation and storage capacity Parameters ---------- n : pypsa.Network Optimized network linewidth_factor : float, optional Scale factor of line widths. The default is 5e3. gen_size_factor : float, optional Scale factor of generator capacities. The default is 5e4. sus_size_factor : float, optional Scale factor of storage capacities. The default is 1e4. carrier_colors : pd.Series, optional Colors of the carriers. The default is None. carrier_names : pd.Series, optional Nice names of the carriers. The default is None. figsize : tuple, optional figsize of resulting image. The default is (10, 5). boundaries : tuple, optional Geographical bounds of the geomap. The default is [-10. , 30, 36, 70]. Returns ------- fig, ax Figure and axes of the corresponding plot. """ if carrier_colors is None: carrier_colors = n.carriers.color fallback = pd.Series(n.carriers.index.str.title(), n.carriers.index) carrier_names = n.carriers.nice_name.replace( '', np.nan).fillna(fallback) line_colors = {'cur': "purple", 'exp': to_hex(to_rgba("red", 0.5), True)} gen_sizes = n.generators.groupby(['bus', 'carrier']).p_nom_opt.sum() store_sizes = n.storage_units.groupby(['bus', 'carrier']).p_nom_opt.sum() # PLOT try: import cartopy.crs as ccrs projection = ccrs.EqualEarth() kwargs.setdefault('geomap', '50m') except ImportError: projection = None logger.warn('Could not import cartopy, drawing map disabled') fig, (ax, ax2) = plt.subplots(1, 2, figsize=figsize, subplot_kw={"projection": projection}) n.plot(bus_sizes=gen_sizes / gen_size_factor, bus_colors=carrier_colors, line_widths=n.lines.s_nom_min.div(linewidth_factor), link_widths=n.links.p_nom_min.div(linewidth_factor), line_colors=line_colors['cur'], link_colors=line_colors['cur'], boundaries=boundaries, title='Generation and \nTransmission Capacities', ax=ax, **kwargs) n.plot( bus_sizes=store_sizes / sus_size_factor, bus_colors=carrier_colors, line_widths=( n.lines.s_nom_opt - n.lines.s_nom_min) / linewidth_factor, link_widths=( n.links.p_nom_opt - n.links.p_nom_min) / linewidth_factor, line_colors=line_colors['exp'], link_colors=line_colors['exp'], boundaries=boundaries, title='Storages Capacities and \nTransmission Expansion', ax=ax2, **kwargs) ax.axis('off') # ax.artists[2].set_title('Carriers') # LEGEND add capcacities reference_caps = [10e3, 5e3, 1e3] for axis, scale in zip((ax, ax2), (gen_size_factor, sus_size_factor)): handles = make_legend_circles_for(reference_caps, scale=scale / projected_area_factor(axis)**2 / 3, facecolor="w", edgecolor='grey', alpha=.5) labels = ["{} GW".format(int(s / 1e3)) for s in reference_caps] handler_map = make_handler_map_to_scale_circles_as_in(axis) l2 = axis.legend(handles, labels, framealpha=0.7, loc="upper left", bbox_to_anchor=(0., 1), frameon=True, # edgecolor='w', title='Capacity', handler_map=handler_map) axis.add_artist(l2) reference_caps.pop(0) # LEGEND Transmission handles, labels = [], [] for s in (10, 5): handles.append(plt.Line2D([0], [0], color=line_colors['cur'], linewidth=s * 1e3 / linewidth_factor)) labels.append("/") for s in (10, 5): handles.append(plt.Line2D([0], [0], color=line_colors['exp'], linewidth=s * 1e3 / linewidth_factor)) labels.append("{} GW".format(s)) fig.artists.append(fig.legend(handles, labels, loc="lower left", bbox_to_anchor=(1., .0), frameon=False, ncol=2, columnspacing=0.5, title='Transmission Exist./Exp.')) # legend generation colors colors = carrier_colors[n.generators.carrier.unique()] if carrier_names is not None: colors = colors.rename(carrier_names) fig.artists.append(fig.legend(*handles_labels_for(colors), loc='upper left', bbox_to_anchor=(1, 1), frameon=False, title='Generation carrier')) # legend storage colors colors = carrier_colors[n.storage_units.carrier.unique()] if carrier_names is not None: colors = colors.rename(carrier_names) fig.artists.append(fig.legend(*handles_labels_for(colors), loc='upper left', bbox_to_anchor=(1, 0.55), frameon=False, title='Storage carrier')) fig.canvas.draw() fig.tight_layout() return fig, (ax, ax2)
) regions.loc[[sink]].plot(ax=ax, transform=ccrs.PlateCarree(), aspect='equal') legend_colors = (n.carriers.set_index('nice_name').color.append( emission_color.rename(to_explanation))) fig.legend( *ntl.plot.handles_labels_for(legend_colors), loc="upper left", bbox_to_anchor=(1, 1), title='Carrier', frameon=False, ) # legend generator capacities reference_caps = [500e6, 100e6] scale = 1 / bus_scale / projected_area_factor(ax)**2 handles = make_legend_circles_for(reference_caps, scale=scale, facecolor="w", edgecolor='grey', alpha=.5) labels = ["%iM €" % (s / 1e6) for s in reference_caps] handler_map = make_handler_map_to_scale_circles_as_in(ax) legend = fig.legend(handles, labels, loc="upper left", bbox_to_anchor=(1., 0.4), frameon=False, handler_map=handler_map) fig.add_artist(legend)
line_widths=line_widths / branch_sum * branch_scale, link_widths=link_widths / branch_sum * branch_scale, ax=ax, geomap='10m', boundaries=regions.total_bounds[[0, 2, 1, 3]], ) regions.plot(ax=ax, transform=ccrs.PlateCarree(), aspect='equal', color='white', lw=0.2, edgecolor='grey') # legend generator capacities reference_caps = [50e6, 10e6] scale = oneports.sum() / bus_scale / projected_area_factor(ax)**2 handles = make_legend_circles_for(reference_caps, scale=scale, facecolor="w", edgecolor='grey', alpha=.5) labels = ["%iM €" % (s / 1e6) for s in reference_caps] handler_map = make_handler_map_to_scale_circles_as_in(ax) legend = ax.legend(handles, labels, loc="lower center", bbox_to_anchor=(0.3, 1), frameon=False, handler_map=handler_map) ax.add_artist(legend)