View gist:38cd74926c225a8b4ef4be3a4e349bc1
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. |
View 2_to_4_tabs_ipynb.sh
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%.*}"; | |
View vid_from_mpl_plots.py
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') |
View scatter_categorical_fixedLegend.txt
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], |