Last active
May 10, 2020 12:38
-
-
Save WhereIsLucas/7029f8b1fdc6015ea119653633a97fdc to your computer and use it in GitHub Desktop.
Plotter.py
This file contains hidden or 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 os.path | |
import matplotlib.animation as animation | |
import matplotlib.pyplot as plt | |
import numpy as np | |
types = ['float', 'float', 'float', 'float', 'float', 'float', 'float'] | |
data = [] | |
# Set up formatting for the movie files | |
Writer = animation.writers['ffmpeg'] | |
writer = Writer(fps=15, metadata=dict(artist='Lucas H'), bitrate=1800) | |
fig = plt.figure(figsize=(7, 7)) | |
# this counts the number of frames | |
path = "./datas/" | |
num_files = len([f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]) | |
print(num_files) | |
totalFrames = num_files | |
for i in range(0, totalFrames): | |
fileName = path + "/grain" + str(i) + ".txt" | |
data.insert(i, np.genfromtxt(fileName, | |
delimiter=',', | |
dtype=types, | |
names=["ID", 'x', 'y', 'vx', 'vy', 'theta', 'radius'])) | |
showingFrame = 0 | |
scat = plt.scatter(data[showingFrame]["x"], data[showingFrame]['y'], alpha=0.5, s=data[0]['radius'] * 1 * 100000) | |
plt.title('Scatter plot test') | |
# plt.gca().set_aspect('equal', adjustable='box') | |
plt.axis("equal") | |
plt.xlim(-.4, .4) | |
plt.ylim(-.4, .4) | |
plt.xlabel('x') | |
plt.ylabel('y') | |
# plt.show() | |
def update(frame_number): | |
scat.set_offsets(np.c_[data[frame_number]["x"], data[frame_number]["y"]]) | |
animation = animation.FuncAnimation(fig, update, interval=10, frames=totalFrames) | |
# plt.show() | |
animation.save('exports/im.mp4', writer=writer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
j'aime