Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. # initialize the signals
  2. POWER=0, FIRE=0, ARMED=0, LED=OFF, COUNT=N.
  3. # turn on the power
  4. POWER=1 => LED=GREEN.
  5. # fire once to arm
  6. FIRE=1.
  7. FIRE => ARMED=1.
  8. FIRE=0.
  9. # fire a second time
  10. FIRE=1.
  11. FIRE, ARMED => LED=RED;
  12. FIRE => COUNT="N+1".
  13.  
  14. #! /usr/bin/env python
  15. #coding=utf-8
  16. """
  17. mpl_time.py Example of generating timing diagrams in matplotlib.
  18. """
  19.  
  20. import matplotlib.pyplot as plt
  21. from datetime import datetime, timedelta
  22. import random
  23. # assuming your timing data in a csv file you could import csv and read the data
  24.  
  25. def GetData(samplelen=20):
  26. """ As I don't wish to spend the time generating a csv file I will dummy!"""
  27. data = {'t':[], 's1':[], 's2':[], 's3':[],}
  28. vals = {'s1':0, 's2':0, 's3':0,}
  29. t_current = 0.0 #datetime.now()
  30. t_increment = 0.01 #timedelta(0, 100)
  31. for step in xrange(samplelen*10):
  32. data['t'].append(t_current)
  33. if step % 9 == 0:
  34. for s in ['s1', 's2']:
  35. vals[s] = random.choice([0, 1])
  36. vals['s3'] = random.choice([0, 1])
  37. for s in ['s1', 's2', 's3']:
  38. data[s].append(vals[s])
  39. t_current = t_current + t_increment
  40. return data
  41.  
  42. def PlotData(data, timename='t'):
  43. """
  44. Expects a dictionary of named items with a list of states in all but the
  45. time axis named in it.
  46. """
  47. plotlist = sorted([k for k in data.keys() if k < timename])
  48. print plotlist
  49. timeax = data.get(timename)
  50. print timeax
  51. f, axes = plt.subplots(len(plotlist), sharex=True, sharey=True)
  52. for k, ax in zip(plotlist, axes):
  53. #assert isinstance(ax, plt.axes.subplot)
  54. ax.set_title(k)
  55. ax.plot(timeax, data[k])
  56. ax.set_ybound(1.2, -0.2)
  57. #ax.set_xbound(timeax[0], timeax[-1])
  58.  
  59. # Fine-tune figure; make subplots close to each other and hide x ticks for
  60. # all but bottom plot.
  61. f.subplots_adjust(hspace=0)
  62. plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
  63. plt.show()
  64.  
  65. if __name__ == "__main__":
  66. DATA = GetData(50)
  67. print DATA
  68. PlotData(DATA)
  69.  
  70. {signal: [
  71. {name: 'clk', wave: 'p.....|...'},
  72. {name: 'dat', wave: 'x.345x|=.x', data: ['head', 'body', 'tail', 'data']},
  73. {name: 'req', wave: '0.1..0|1.0'},
  74. {},
  75. {name: 'ack', wave: '1.....|01.'}
  76. ]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement