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 numpy as np | |
import time | |
import matplotlib.pyplot as plt | |
# See: https://x.com/AlexanderRKlotz/status/1848152886443753574 | |
# With h/t to chatgpt. | |
""" | |
Output should look sth like: |
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
def vec_to_angle(v, degrees=False): | |
"""Convert any vector to its radian equivalent (0-2pi). If degrees, convert output to degrees. | |
""" | |
a = np.arctan2(v[:,1], v[:,0]) # returns -180 to 180 | |
a[a<0] += 2*np.pi # convert to 0-360 | |
if degrees: a = a / np.pi * 180 | |
return a | |
def angle_to_vec(a, degrees=False): | |
"""Convert an angle to a unit vector. If degrees, convert back to radians before computing. |
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
#!/bin/zsh | |
# Will convert all files in current dir, recursively. Could be modified to take args but I'm lazy! | |
for filename in ./**/*.ipynb; do | |
# Split the file name | |
extension="${filename##*.}"; | |
filename_noext="${filename%.*}"; | |
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 | |
import imageio as iio | |
def my_plt_plotting_func(data): | |
plt.plot(data) # can be as extensive as you want, as long as it just makes a single pyplot fig | |
def write_frame(data, vid): | |
my_plt_plotting_func(data) | |
plt.savefig('current_frame.tiff') |
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 numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.lines import Line2D | |
x = np.arange(0, 2*np.pi, 0.1) | |
y = np.sin(x) | |
clusters = np.random.randint(0,5, size=(x.shape[0],)) | |
colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] | |
plt.scatter(x, y, c=[colors[c] for c in clusters]) | |
plt.legend(handles=[Line2D([0], |