Advertisement
Guest User

sinegraph.py

a guest
Sep 20th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from pandas import DataFrame
  4. from datetime import datetime, timedelta
  5.  
  6. def draw(plotdict):
  7.     df = DataFrame(plotdict)
  8.     fig, ax = plt.subplots()
  9.     ax.set_ylim([-1,1])
  10.     #fig.subplots_adjust(left=0.10, bottom=0.17, right=0.80, top=0.96, wspace=0, hspace=0)
  11.     for key in plotdict.keys():
  12.         if key != "dates":
  13.             df.plot.line(x="dates", y=key, ax=ax)
  14.     plt.grid(b=True, which="major", axis="both")
  15.     plt.figure(figsize=(5,3), dpi=60)
  16.     for tick in ax.xaxis.get_major_ticks():
  17.         tick.label.set_fontsize(8)
  18.         tick.label.set_rotation(45)
  19.     plt.show()
  20.    
  21. def create_plots(): ##this is just to generate some sinewave data and add it to some dates.
  22.     d= datetime.now()
  23.     dates = []
  24.     s1 = np.sin(np.arange(0, 10, 0.1))
  25.     s2 = np.sin(np.arange(1, 10, 0.1))
  26.     s3 = np.sin(np.arange(2, 10, 0.1))
  27.     sinelength = min([len(s1), len(s1), len(s3)])
  28.     s1 = s1[0:sinelength]
  29.     s2 = s2[0:sinelength]
  30.     s2 = s2[0:sinelength]
  31.     for i in range(sinelength):
  32.         d = d + timedelta(days=1)
  33.         dates.append(d.strftime("%d/%m/%Y"))
  34.     plotdict = {'dates':dates, 's1':s1, 's2':s2, 's3':s3}
  35.     draw(plotdict)
  36.    
  37. create_plots()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement