绘制plot事件图的示例

一个事件图,显示具有各种线属性的事件序列。该图以水平和垂直方向显示。

绘制事件集的示例;

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import matplotlib
  4. matplotlib.rcParams['font.size'] = 8.0
  5. # Fixing random state for reproducibility
  6. np.random.seed(19680801)
  7. # create random data
  8. data1 = np.random.random([6, 50])
  9. # set different colors for each set of positions
  10. colors1 = np.array([[1, 0, 0],
  11. [0, 1, 0],
  12. [0, 0, 1],
  13. [1, 1, 0],
  14. [1, 0, 1],
  15. [0, 1, 1]])
  16. # set different line properties for each set of positions
  17. # note that some overlap
  18. lineoffsets1 = np.array([-15, -3, 1, 1.5, 6, 10])
  19. linelengths1 = [5, 2, 1, 1, 3, 1.5]
  20. fig, axs = plt.subplots(2, 2)
  21. # create a horizontal plot
  22. axs[0, 0].eventplot(data1, colors=colors1, lineoffsets=lineoffsets1,
  23. linelengths=linelengths1)
  24. # create a vertical plot
  25. axs[1, 0].eventplot(data1, colors=colors1, lineoffsets=lineoffsets1,
  26. linelengths=linelengths1, orientation='vertical')
  27. # create another set of random data.
  28. # the gamma distribution is only used fo aesthetic purposes
  29. data2 = np.random.gamma(4, size=[60, 50])
  30. # use individual values for the parameters this time
  31. # these values will be used for all data sets (except lineoffsets2, which
  32. # sets the increment between each data set in this usage)
  33. colors2 = [[0, 0, 0]]
  34. lineoffsets2 = 1
  35. linelengths2 = 1
  36. # create a horizontal plot
  37. axs[0, 1].eventplot(data2, colors=colors2, lineoffsets=lineoffsets2,
  38. linelengths=linelengths2)
  39. # create a vertical plot
  40. axs[1, 1].eventplot(data2, colors=colors2, lineoffsets=lineoffsets2,
  41. linelengths=linelengths2, orientation='vertical')
  42. plt.show()

下载这个示例