Skip to content

Instantly share code, notes, and snippets.

View cvanelteren's full-sized avatar

Casper van Elteren cvanelteren

View GitHub Profile
@cvanelteren
cvanelteren / matplotlib_animation.gif
Last active September 21, 2022 13:22
matplotlib animation
here is a gif
import networkx as nx, numpy as np, matplotlib.pyplot as plt
np.random.seed(0)
g = nx.florentine_families_graph()
# g = nx.krackhardt_kite_graph()
pos = nx.random_layout(g)
x = {node: p[0] for node, p in pos.items()}
y = {node: p[1] for node, p in pos.items()}
l = {node: node for node in g.nodes()}
@cvanelteren
cvanelteren / networkx_animation.py
Created August 9, 2021 13:23
Simple graph animator
import matplotlib.pyplot as plt
import numpy as np, networkx as nx
from matplotlib.collections import LineCollection
def setup(
g: nx.Graph, layout: dict or callable, node_kwargs={}, edge_kwargs={}, **kwargs
) -> list:
"""
Simple setup: creates scatter points and line segments (graph)
@cvanelteren
cvanelteren / latex_tips.md
Last active July 1, 2021 11:20
Random latex shananigans
@cvanelteren
cvanelteren / create_arxiv.sh
Last active July 1, 2021 11:31
Arxiv paper creation
cp ~/library.bib library.bib
# flatex is a python package
# flatex paper.tex arxiv_paper.tex
# now called pydflatex?
pydflatex paper.tex arxiv_paper.tex
arxiv-collector arxiv_paper.tex
@cvanelteren
cvanelteren / complex_layout.py
Created June 10, 2021 13:47
Example of mosaic_layouts
import matplotlib.pyplot as plt, cmasher as cmr
import numpy as np
layout = np.zeros((10, 10), dtype = object)
layout[-1, :] = np.arange(1, 11)
layout[:, -1] = np.arange(20, 30)
fig = plt.figure(constrained_layout = 1)
axs = fig.subplot_mosaic(layout)
ax = axs.get(-1)
@cvanelteren
cvanelteren / gaussian_roll.py
Created June 7, 2021 07:51
Gaussian roll - matplotlib animation for 3d line plots with colored segments
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Line3DCollection
fig, ax = plt.subplots(subplot_kw = dict(projection = '3d'))
# generate data
x = np.linspace(-5, 5, 500)
y = np.linspace(-5, 5, 500)
z = np.exp(-(x - 2)**2)
@cvanelteren
cvanelteren / simple_progbar
Created April 15, 2021 14:29
Creating a simple progression bar
import sys, time
class progbar:
def __init__(self, x, stream = sys.stdout,
char = "#"):
self.x = x
self.stream = stream
self.char = char
def __iter__(self):
self.n = len(self.x)
@cvanelteren
cvanelteren / discrete_colorbar.py
Last active April 6, 2021 10:18
Small utility to create a discrete matplotlib colormap
# Original by Jake VanderPlas
# https://gist.github.com/jakevdp/91077b0cae40f8f8244a
# License: BSD-style
# cvanelteren: small edit since the original was not compatible with latest mpl
import matplotlib.pyplot as plt, numpy as np
def discrete_cmap(N, base_cmap=None):
"""Create an N-bin discrete colormap from the specified input map"""
# Note that if base_cmap is a string or None, you can simply do
# return plt.cm.get_cmap(base_cmap, N)
test-microphone() {
arecord -vvv -f dat /dev/null
}