Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ad6e75

Browse files
committed
add eventplot demo
1 parent c25c815 commit 0ad6e75

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python
2+
# -*- Coding:utf-8 -*-
3+
'''an eventplot showing sequences of events with various line properties
4+
the plot is shown in both horizontal and vertical orientations'''
5+
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
# set the random seed
10+
np.random.seed(0)
11+
12+
# create random data
13+
data1 = np.random.random([6, 50])
14+
15+
# set different colors for each set of positions
16+
colors1 = np.array([[1, 0, 0],
17+
[0, 1, 0],
18+
[0, 0, 1],
19+
[1, 1, 0],
20+
[1, 0, 1],
21+
[0, 1, 1]])
22+
23+
# set different line properties for each set of positions
24+
# note that some overlap
25+
lineoffsets1 = np.array([-15, -3, 1, 1.5, 6, 10])
26+
linelengths1 = [5, 2, 1, 1, 3, 1.5]
27+
28+
fig = plt.figure()
29+
30+
# create a horizontal plot
31+
ax1 = fig.add_subplot(221)
32+
ax1.eventplot(data1, colors=colors1, lineoffsets=lineoffsets1,
33+
linelengths=linelengths1)
34+
ax1.set_title('horizontal eventplot 1')
35+
36+
37+
# create a vertical plot
38+
ax2 = fig.add_subplot(223)
39+
ax2.eventplot(data1, colors=colors1, lineoffsets=lineoffsets1,
40+
linelengths=linelengths1, orientation='vertical')
41+
ax2.set_title('vertical eventplot 1')
42+
43+
# create another set of random data.
44+
# the gamma distribution is only used fo aesthetic purposes
45+
data2 = np.random.gamma(4, size=[60, 50])
46+
47+
# use individual values for the parameters this time
48+
# these values will be used for all data sets (except lineoffsets2, which
49+
# sets the increment between each data set in this usage)
50+
colors2 = [[0, 0, 0]]
51+
lineoffsets2 = 1
52+
linelengths2 = 1
53+
54+
# create a horizontal plot
55+
ax1 = fig.add_subplot(222)
56+
ax1.eventplot(data2, colors=colors2, lineoffsets=lineoffsets2,
57+
linelengths=linelengths2)
58+
ax1.set_title('horizontal eventplot 2')
59+
60+
61+
# create a vertical plot
62+
ax2 = fig.add_subplot(224)
63+
ax2.eventplot(data2, colors=colors2, lineoffsets=lineoffsets2,
64+
linelengths=linelengths2, orientation='vertical')
65+
ax2.set_title('vertical eventplot 2')
66+
67+
fig.show()

0 commit comments

Comments
 (0)