Created
November 29, 2018 07:24
-
-
Save yinguobing/4f390f4c3e1c904f472766a9bae9cb9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
DURATION = 12 | |
FPS = 25 | |
START = 0 | |
STEPS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | |
if __name__ == "__main__": | |
# Generate data. | |
x = [] | |
for i in np.arange(FPS * DURATION): | |
if i < START: | |
x.append(0) | |
elif i == START: | |
x.append(1) | |
else: # i > START: | |
t = int(i / FPS) | |
STEP = STEPS[t] | |
if (i - START) % STEP == 0: | |
x.append(1) | |
else: | |
x.append(0) | |
x = np.reshape(x, [DURATION, FPS]).T | |
# Draw the density. | |
plt.spy(x, precision=0, markersize=7, markerfacecoloralt='green', origin='lower') | |
# Set labels in image. | |
ylabels = [str(s) for s in np.arange(1, 25) if s % 2 == 0] | |
xlabels = [str(s) for s in np.arange(1, 13) if s % 2 == 0] | |
plt.yticks(np.arange(1, 25, step=2), labels=ylabels) | |
plt.xticks(np.arange(1, 12, step=2), labels=xlabels) | |
plt.ylabel('Frame') | |
plt.xlabel('Time (s)') | |
# Set figure title. | |
plt.title('Sampling map (3rd try)') | |
# Show the result. | |
plt.gca().invert_yaxis() | |
plt.gca().xaxis.set_ticks_position('bottom') | |
plt.savefig('sample_map_nu_s{}.png'.format(STEP), | |
bbox_inches='tight', pad_inches=0.2) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment