geomap.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # conda activate GEOGRAPHICMAP
  2. # conda install basemap
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. from mpl_toolkits.basemap import Basemap
  6. plt.figure(figsize=(8, 8))
  7. m = Basemap(projection='ortho', resolution=None, lat_0=60, lon_0=30) # широта и долгота
  8. m.bluemarble(scale=0.5)
  9. x, y = m(-21.939852, 64.147182)
  10. plt.plot(x, y, 'ow', markersize=3)
  11. plt.text(x, y, 'Reykjavík', fontsize=8, color='orange')
  12. x1, y1 = m(49.105579, 55.795366)
  13. plt.plot(x1, y1, 'or', markersize=3)
  14. plt.text(x1, y1, 'Kazan', fontsize=8, color='orange')
  15. x2, y2 = m(121.467864, 31.231745)
  16. plt.plot(x2, y2, 'oy', markersize=3)
  17. plt.text(x2, y2, 'Shànghǎi', fontsize=8, color='orange')
  18. x3, y3 = m(46.735549, 24.665633)
  19. plt.plot(x3, y3, 'og', markersize=3)
  20. plt.text(x3, y3, 'ar-Riyāḍ', fontsize=8, color='black')
  21. x4, y4 = m(-74.004105, 40.715881)
  22. plt.plot(x4, y4, 'or', markersize=3)
  23. plt.text(x4, y4, 'New York City', fontsize=8, color='orange')
  24. # plt.show()
  25. fig = plt.figure(figsize=(8, 8))
  26. m = Basemap(projection='lcc', resolution=None,
  27. width=6E6, height=6E6,
  28. lat_0=50., lon_0=0.0,)
  29. m.etopo(scale=0.5, alpha=0.5)
  30. # Map (long, lat) to (x, y) for plotting
  31. x, y = m(-0.12574, 51.5085)
  32. plt.plot(x, y, 'ok', markersize=5)
  33. plt.text(x, y, 'London', fontsize=12)
  34. x1, y1 = m(2.350974, 48.856551)
  35. plt.plot(x1, y1, 'ob', markersize=5)
  36. plt.text(x1, y1, 'Paris', fontsize=12)
  37. # plt.show()
  38. from itertools import chain
  39. def draw_map(m, scale=0.2):
  40. # draw a shaded-relief image
  41. m.shadedrelief(scale=scale)
  42. # lats and longs are returned as a dictionary
  43. lats = m.drawparallels(np.linspace(-90, 90, 13))
  44. lons = m.drawmeridians(np.linspace(-180, 180, 13))
  45. # keys contain the plt.Line2D instances
  46. lat_lines = chain(*(tup[1][0] for tup in lats.items()))
  47. lon_lines = chain(*(tup[1][0] for tup in lons.items()))
  48. all_lines = chain(lat_lines, lon_lines)
  49. # cycle through these lines and set the desired style
  50. for line in all_lines:
  51. line.set(linestyle='-', alpha=0.3, color='w')
  52. fig = plt.figure(figsize=(8, 8))
  53. m = Basemap(projection='ortho', resolution=None,
  54. lat_0=50, lon_0=0)
  55. draw_map(m)
  56. x, y = m(30.313921, 59.938885)
  57. plt.plot(x, y, 'ob', markersize=5)
  58. plt.text(x+1, y+5, 'St. Petersburg', fontsize=6)
  59. x1, y1 = m(4.891469, 52.373194)
  60. plt.plot(x1, y1, 'or', markersize=5)
  61. plt.text(x1+1, y1+5, 'Amsterdam', fontsize=6)
  62. # plt.show()
  63. fig = plt.figure(figsize=(8, 8))
  64. m = Basemap(projection='lcc', resolution=None,
  65. lon_0=0, lat_0=50, lat_1=45, lat_2=55,
  66. width=1.6E7, height=1.2E7)
  67. draw_map(m)
  68. x, y = m(30.313921, 59.938885)
  69. plt.plot(x, y, 'ob', markersize=5)
  70. plt.text(x+1, y+5, 'St. Petersburg', fontsize=6)
  71. # plt.show()
  72. fig = plt.figure(figsize=(8, 6), edgecolor='w')
  73. m = Basemap(projection='moll', resolution=None,
  74. lat_0=0, lon_0=0)
  75. draw_map(m)
  76. x, y = m(30.313921, 59.938885)
  77. plt.plot(x, y, 'or', markersize=5)
  78. plt.text(x+10, y+10, 'St. Petersburg', fontsize=6, color='Black')
  79. plt.show()