Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import datetime as dt
  4. import matplotlib.pyplot as plt # vers 1.3.1
  5. import matplotlib.dates as md
  6. import matplotlib.patches as mpatches
  7. import matplotlib.transforms as transform
  8.  
  9. x_offset = dt.timedelta(hours=4)
  10.  
  11. fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, sharex=True)
  12.  
  13. x0 = [1558065600, 1558152000, 1558238400, 1558324800, 1558411200, 1558497600, 1558584000, 1558670400] # <-- Date
  14. x1 = [dt.datetime.fromtimestamp(_) for _ in x0]
  15.  
  16. # ================================= Subplot 1 =================================
  17. y = [83.12, 82.45, 87.51, 85.27, 75.85, 81.72, 91.16, 86.74] # <-- Temperature
  18.  
  19. ax0.set_title('high temperature')
  20. ax0.plot(x1, y)
  21. ax0.set_xlim(min(x1) - x_offset, max(x1) + x_offset)
  22. myFmt = md.DateFormatter('%m-%d')
  23. ax1.xaxis.set_major_formatter(myFmt)
  24.  
  25. # ================================= Subplot 2 =================================
  26. y = [4.25, 2.03, 7.77, 9.85, 6.73, 4.47, 5.97, 7.24] # <-- Wind Speed
  27. z = [251, 86, 171, 224, 331, 147, 265, 319] # <-- Wind Bearing
  28. data = zip(x1, y, z)
  29.  
  30. ax1.set_title('wind')
  31. ax1.plot(x1, y)
  32. ax1.set_ylim(0, max(y) + 1)
  33.  
  34. for _ in data:
  35. day = md.date2num(_[0])
  36. location = _[1]
  37. bearing = _[2] # <-- Rotate patch based on this
  38.  
  39. arr = mpatches.FancyArrowPatch(posA=(day, location), posB=(day, location + 0.1), arrowstyle='Simple', color='red', lw=0)
  40. arr.set_arrowstyle("fancy", head_length=10, head_width=10)
  41.  
  42. # <-- Perform elusive transformation -->
  43.  
  44. ax1.add_patch(arr)
  45.  
  46. # ================================= Subplot 3 =================================
  47. # Precip intensity is in inches of liquid rain per hour.
  48. y = [_ * 24 for _ in [0.0021, 0.0035, 0.0018, 0.0017, 0.0001, 0.0000, 0.0001, 0.0003]] # <-- Precip
  49.  
  50. ax2.set_title('precip intensity')
  51. ax2.plot(x1, y)
  52.  
  53. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement