Legend for Line Loading Plot

143 views
Skip to first unread message

Elias Althoff

unread,
Jan 12, 2022, 10:43:06 AM1/12/22
to pypsa
Dear all,

is there a built in way to activate the legend for the line_loading plot? I am trying to create a plot that shows the hours in which the lines are overloaded. It works so far, but I somehow cant manage to add a legend to the plot.

This is what I am using right now:

loading_factors = loading_factors[loading_factors > 1].count()
fig,ax = plt.subplots(1,1,subplot_kw={"projection":ccrs.PlateCarree()})
fig.set_size_inches(6,6)
handles = loading_factors      
network.plot(ax=ax,bus_sizes=0.001,line_colors=loading_factors,line_cmap=plt.cm.jet,title="Anzahl Stunden mit Überlastung")
ax.legend(handles)
fig.tight_layout()

I know this is more a coding problem than a pypsa problem, but Im guessing there are some more built in functions in the plots than I know of. So maybe there is an easy solution for this. 

Best wishes,
Elias

Fabian Neumann

unread,
Jan 13, 2022, 11:49:36 AM1/13/22
to Elias Althoff, pypsa
Hi Elias,

yes, that's a pain point. I use the following, but it's not great:

import matplotlib.colors as mcolors
import matplotlib.pyplot as plt

fig, ax = ...

cmap= plt.cm.OrRd
norm = mcolors.Normalize(vmin=0, vmax=100)
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
sm.set_array([])

colors = list(map(mcolors.to_hex, cmap(norm(line_loading))))

n.plot(ax=ax, line_colors=colors, ...)

plt.colorbar(sm, orientation='vertical', shrink=0.7, ax=ax, label=...)

Best wishes,

Fabian N
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/731c2804-9ed6-438c-873f-f0aa03d91a5bn%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/731c2804-9ed6-438c-873f-f0aa03d91a5bn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Dr.-Ing.
Fabian Neumann (he/him)
Postdoctoral Researcher

Department of Digital Transformation in Energy Systems
Institute of Energy Technology
Technische Universität Berlin

Group website: https://tub-ensys.github.io
Personal website: https://neumann.fyi

Zoom: https://tu-berlin.zoom.us/my/fneum
Schedule Meeting: https://calendly.com/fneum

Visitor Address:
Einsteinufer 25 (TA 8)
10587 Berlin

My working hours may not be your working hours. Do not feel pressure to
reply to this email outside your working hours.
Reply all
Reply to author
Forward
0 new messages