Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import datetime as dt
- import matplotlib.pyplot as plt # vers 1.3.1
- import matplotlib.dates as md
- import matplotlib.patches as mpatches
- import matplotlib.transforms as transform
- x_offset = dt.timedelta(hours=4)
- fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, sharex=True)
- x0 = [1558065600, 1558152000, 1558238400, 1558324800, 1558411200, 1558497600, 1558584000, 1558670400] # <-- Date
- x1 = [dt.datetime.fromtimestamp(_) for _ in x0]
- # ================================= Subplot 1 =================================
- y = [83.12, 82.45, 87.51, 85.27, 75.85, 81.72, 91.16, 86.74] # <-- Temperature
- ax0.set_title('high temperature')
- ax0.plot(x1, y)
- ax0.set_xlim(min(x1) - x_offset, max(x1) + x_offset)
- myFmt = md.DateFormatter('%m-%d')
- ax1.xaxis.set_major_formatter(myFmt)
- # ================================= Subplot 2 =================================
- y = [4.25, 2.03, 7.77, 9.85, 6.73, 4.47, 5.97, 7.24] # <-- Wind Speed
- z = [251, 86, 171, 224, 331, 147, 265, 319] # <-- Wind Bearing
- data = zip(x1, y, z)
- ax1.set_title('wind')
- ax1.plot(x1, y)
- ax1.set_ylim(0, max(y) + 1)
- for _ in data:
- day = md.date2num(_[0])
- location = _[1]
- bearing = _[2] # <-- Rotate patch based on this
- arr = mpatches.FancyArrowPatch(posA=(day, location), posB=(day, location + 0.1), arrowstyle='Simple', color='red', lw=0)
- arr.set_arrowstyle("fancy", head_length=10, head_width=10)
- # <-- Perform elusive transformation -->
- ax1.add_patch(arr)
- # ================================= Subplot 3 =================================
- # Precip intensity is in inches of liquid rain per hour.
- y = [_ * 24 for _ in [0.0021, 0.0035, 0.0018, 0.0017, 0.0001, 0.0000, 0.0001, 0.0003]] # <-- Precip
- ax2.set_title('precip intensity')
- ax2.plot(x1, y)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement