import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon,Rectangle,FancyArrowPatch
T="#222222";G="#555555";EAU="#2c7fb8";ROC="#b9a88a";PV="#f2b705";NEUF="#d62828";ETE="#f08c00";HIVER="#1c4f9c"
V21=[453,447,552,593,641,640,661,635,573,529,450,429]
V22=[559,543,552,593,537,539,557,531,573,529,553,535]
MOIS=["J","F","M","A","M","J","J","A","S","O","N","D"]
fig=plt.figure(figsize=(18,13.5),dpi=110)
fig.patch.set_facecolor("white")
ax=fig.add_axes([0.02,0.42,0.96,0.52])
ax.set_xlim(-2.5,25);ax.set_ylim(-30,420);ax.axis("off")
ax.add_patch(Polygon([(-2.5,-30),(-2.5,380),(2,380),(5.5,360),(8.3,350),(8.3,170),(9.2,170),(12,150),(16,150),(20,160),(25,170),(25,-30)],closed=True,color=ROC,lw=0))
ax.add_patch(Polygon([(-2.5,350),(8.3,350),(8.3,300),(-2.5,300)],closed=True,color=EAU,alpha=0.9,lw=0))
ax.add_patch(Polygon([(-2.5,350),(8.3,350),(8.3,338),(-2.5,338)],closed=True,color=ETE,alpha=0.95,lw=0))
ax.add_patch(Polygon([(9.2,170),(25,170),(25,150),(12,150),(9.2,160)],closed=True,color=EAU,alpha=0.9,lw=0))
ax.add_patch(Polygon([(9.2,170),(25,170),(25,163),(9.2,163)],closed=True,color=HIVER,alpha=0.95,lw=0))
ax.add_patch(Polygon([(8.3,350),(8.3,170),(9.2,170),(9.2,350)],closed=True,color="#8d8d8d",lw=0))
ax.text(2.8,344,"THE SEASONAL RESERVE: 1 km³ kept from May to August, 412 GWh",ha="center",va="center",fontsize=10.5,color="white",weight="bold")
ax.text(2.8,318,"Lake Mead, 32 km³: the upper lake already exists",ha="center",va="center",fontsize=11,color="white",weight="bold")
ax.text(17.2,166.5,"Lake Mohave, 2.2 km³: it lends 1 km³ to the valley in summer and gets it back in winter",ha="center",va="center",fontsize=10.5,color="white",weight="bold")
ax.text(18,156,"the lower lake already exists (Davis Dam, 108 km downstream)",ha="center",va="center",fontsize=9.5,color="white")
ax.text(8.75,365,"Hoover Dam\n221 m, 2,080 MW substation",ha="center",va="bottom",fontsize=10.5,color=T,weight="bold")
ax.add_patch(Rectangle((9.3,172),1.6,30,color="#444444"))
ax.text(5.3,238,"17 existing turbines, 2,080 MW\nSUMMER: they run 36% less\nWINTER: they return the reserve in the evening",ha="center",va="center",fontsize=9.8,color=T)
ax.add_patch(FancyArrowPatch((8.3,330),(9.5,190),arrowstyle="-|>",mutation_scale=18,lw=3,color="#444444"))
ax.add_patch(Rectangle((11.6,172),1.6,22,color=NEUF))
ax.text(12.9,206,"V21: 300 MW pumping station\n(midday sun returned in the evening)",ha="left",va="bottom",fontsize=9.5,color=NEUF,weight="bold")
ax.plot([12.4,12.4,7.5],[194,320,320],color=NEUF,lw=3.5,ls="--",zorder=6)
ax.text(12.9,262,"V21: 2 km tunnel in the rock, 170 m",ha="left",va="bottom",fontsize=9.5,color=NEUF,weight="bold")
for i in range(9):
    x=15.5+i*1.0
    ax.add_patch(Polygon([(x-0.35,172),(x+0.35,172),(x+0.45,186),(x-0.25,186)],closed=True,color=PV,lw=0))
ax.text(19.5,195,"V21: 1,500 MWp of trackers,\n39% of their year from May to August",ha="center",va="bottom",fontsize=10,color=T,weight="bold")
ax.text(3,62,"SUMMER (May to August): the sun overflows. The dam holds back 36% of the river's water in Lake Mead;\nthe valley still gets its water, taken from Lake Mohave, which drops by 1 km³.\nWINTER (November to February): the dam returns the 412 GWh in the evening through its turbines, Lake Mohave refills.\nNothing is built, nothing is pumped for the season, no loss: it is an operating rule.",ha="left",va="center",fontsize=11,color=T,bbox=dict(boxstyle="round,pad=0.5",fc="white",ec=G))
ax.plot([20,24],[-18,-18],color=T,lw=3);ax.text(24,-10,"4 km (horizontal); heights are in metres, the vertical scale is stretched",ha="right",fontsize=9,color=G)
ax.plot([24.5,24.5],[170,370],color=T,lw=2);ax.text(24.7,270,"200 m",va="center",fontsize=9,color=G)
bx=fig.add_axes([0.07,0.07,0.86,0.27])
xs=range(12)
bx.bar([x-0.2 for x in xs],V21,width=0.4,color=ETE,label="V21 Barrage alone: 27% of the year from November to February, 39% from May to August")
bx.bar([x+0.2 for x in xs],V22,width=0.4,color=HIVER,label="V22 Saison: 33% from November to February, 33% from May to August")
bx.set_xticks(list(xs));bx.set_xticklabels(MOIS,fontsize=12)
bx.set_ylabel("GWh per month, dam and Hydroloop",fontsize=11)
bx.set_ylim(0,900)
for x,(a,b) in enumerate(zip(V21,V22)):
    bx.text(x-0.2,a+8,str(a),ha="center",fontsize=8.5,color=G)
    bx.text(x+0.2,b+8,str(b),ha="center",fontsize=8.5,color=T)
bx.legend(loc="upper center",fontsize=11,ncol=1,frameon=False)
for s in ("top","right"):
    bx.spines[s].set_visible(False)
fig.suptitle("Hydroloop Muhleisen 2026 V22 Saison on the Hoover Dam: summer kept for winter in a lake that exists, without building anything. www.mulo.world, 20/11/2026, CC BY 4.0",fontsize=13,color=T,y=0.975)
plt.savefig("schema_hydroloop_muhleisen_2026_v22_saison_hoover.png",dpi=110,facecolor="white")
print("ok")
