xdenisx

dates

Nov 21st, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. import matplotlib as mpl
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import datetime as dt
  5. fig = plt.figure()
  6. ax2 = fig.add_subplot(212)
  7. date2_1 = dt.datetime(2008, 9, 23)
  8. date2_2 = dt.datetime(2008, 10, 3)
  9. delta2 = dt.timedelta(days=1)
  10. dates2 = mpl.dates.drange(date2_1, date2_2, delta2)
  11. y2 = np.random.rand(len(dates2))
  12. ax2.plot_date(dates2, y2, linestyle='-');
  13. dateFmt = mpl.dates.DateFormatter('%Y-%m-%d')
  14. ax2.xaxis.set_major_formatter(dateFmt)
  15. daysLoc = mpl.dates.DayLocator()
  16. hoursLoc = mpl.dates.HourLocator(interval=6)
  17. ax2.xaxis.set_major_locator(daysLoc)
  18. ax2.xaxis.set_minor_locator(hoursLoc)
  19. fig.autofmt_xdate(bottom=0.18) # adjust for date labels display
  20. fig.subplots_adjust(left=0.18)
  21. ax1 = fig.add_subplot(211)
  22. date1_1 = dt.datetime(2008, 9, 23)
  23. date1_2 = dt.datetime(2009, 2, 16)
  24. delta1 = dt.timedelta(days=10)
  25. dates1 = mpl.dates.drange(date1_1, date1_2, delta1)
  26. y1 = np.random.rand(len(dates1))
  27. ax1.plot_date(dates1, y1, linestyle='-');
  28. monthsLoc = mpl.dates.MonthLocator()
  29. weeksLoc = mpl.dates.WeekdayLocator()
  30. ax1.xaxis.set_major_locator(monthsLoc)
  31. ax1.xaxis.set_minor_locator(weeksLoc)
  32. monthsFmt = mpl.dates.DateFormatter('%b')
  33. ax1.xaxis.set_major_formatter(monthsFmt)
  34. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment