map.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Jul 11 09:28:46 2018
  4. @author: BI4
  5. """
  6. from mpl_toolkits.basemap import Basemap
  7. import matplotlib.pyplot as plt
  8. import matplotlib.patches as mpatches
  9. def plotMCT(MCT):
  10. plt.figure(figsize=(24,12))
  11. _map = Basemap(projection='merc',
  12. resolution='l',
  13. llcrnrlon=-93, llcrnrlat=7,
  14. urcrnrlon=-75, urcrnrlat=19)
  15. _map.drawcoastlines()
  16. _map.drawcountries(linewidth=1)
  17. _map.drawmapboundary(fill_color='#99ffff')
  18. _map.fillcontinents(color='#cc9966',lake_color='#99ffff')
  19. _lons = [-90.25,-88.9167,-86.5,-85,-84,-81]
  20. _lats = [15.5,13.7,15,13,10,8.2]
  21. _inter = {'GUAESA':[0,1,'{0} MW'],
  22. 'GUAHON':[0,2,'{0} MW'],
  23. 'ESAHON':[1,2,'{0} MW'],
  24. 'HONNIC':[2,3,'{0} MW'],
  25. 'NICCRC':[3,4,'{0} MW'],
  26. 'CRCPAN':[4,5,'{0} MW']}
  27. _x,_y = _map(_lons,_lats)
  28. for i in _inter:
  29. a = [_x[_inter[i][0]],_x[_inter[i][1]]]
  30. b = [_y[_inter[i][0]],_y[_inter[i][1]]]
  31. if MCT[i][1] >= MCT[i][2] or MCT[i][1] <= MCT[i][0]:
  32. color = 'orangered'
  33. elif MCT[i][1] >= 0.8*MCT[i][2] or MCT[i][1] <= 0.8*MCT[i][0]:
  34. color = 'yellow'
  35. else:
  36. color = 'green'
  37. plt.plot(a,b,'-',color=color,linewidth=3, label=_inter[i][2])
  38. plt.text(sum(a)/2,sum(b)/2,'{:.2f} MW'.format(MCT[i][1]*100),
  39. fontdict={'fontsize': 12, 'backgroundcolor':'#cc9966', 'fontweight':'bold'},
  40. horizontalalignment='center',
  41. verticalalignment='center',)
  42. _map.plot(_x,_y,'o', color='navy',markersize=18)
  43. red_patch = mpatches.Patch(color='red', label='Interconexión al 100% de capacidad')
  44. yellow_patch = mpatches.Patch(color='yellow', label='Interconexión a mas del 80% de capacidad')
  45. green_patch = mpatches.Patch(color='green',label='Interconexión a menos del 80% de capacidad')
  46. plt.legend(handles=[red_patch,yellow_patch,green_patch], loc=3, fontsize=16)
  47. plt.suptitle('Flujos entre Áreas de Control', fontsize =18, fontweight='bold')
  48. plt.show()