map.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Jul 11 09:28:46 2018
  4. @author: BI4
  5. """
  6. import matplotlib.patches as mpatches
  7. import matplotlib.pyplot as plt
  8. from mpl_toolkits.basemap import Basemap
  9. def plotMCT(flujos_inter):
  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 flujos_inter[i][1] >= flujos_inter[i][2] or flujos_inter[i][1] <= flujos_inter[i][0]:
  32. color = 'orangered'
  33. elif flujos_inter[i][1] >= 0.8*flujos_inter[i][2] or flujos_inter[i][1] <= 0.8*flujos_inter[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(flujos_inter[i][1]*100),
  39. fontdict={'fontsize': 12,
  40. 'backgroundcolor': '#cc9966', 'fontweight': 'bold'},
  41. horizontalalignment='center',
  42. verticalalignment='center',)
  43. _map.plot(_x, _y, 'o', color='navy', markersize=18)
  44. red_patch = mpatches.Patch(
  45. color='red', label='Interconexión al 100% de capacidad')
  46. yellow_patch = mpatches.Patch(
  47. color='yellow', label='Interconexión a mas del 80% de capacidad')
  48. green_patch = mpatches.Patch(
  49. color='green', label='Interconexión a menos del 80% de capacidad')
  50. plt.legend(handles=[red_patch, yellow_patch,
  51. green_patch], loc=3, fontsize=16)
  52. plt.suptitle('Flujos entre Áreas de Control',
  53. fontsize=18, fontweight='bold')
  54. plt.show()