Skip to content

Instantly share code, notes, and snippets.

View cvanelteren's full-sized avatar

Casper van Elteren cvanelteren

View GitHub Profile
@cvanelteren
cvanelteren / overly_complicated.py
Created February 26, 2024 15:32
dynamic_plot
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
def fill_between_3d(ax,x1,y1,z1,x2,y2,z2,mode=1,c='steelblue',alpha=0.6):
"""
@cvanelteren
cvanelteren / arc_layout.py
Created October 19, 2023 13:04
Networkx simple hive plot
def arc_layout(
G: nx.Graph, subset_key="subset", radius=1, rotation=0, offset=0
) -> dict:
"""Arc layout for networkx
Provides a layout where a multipartite graph is
displayed on a unit circle. This could provide clear
visuals for data that is highly clustered.
Parameters
@cvanelteren
cvanelteren / multilayer_layout.py
Last active January 8, 2024 20:53
Flat multilayer layout networkx
import proplot as plt, cmasher as cmr, pandas as pd, numpy as np, os, sys, networkx as nx, warnings
def multilayer_layout(
G: nx.Graph,
subset_key="layer",
layout=nx.spring_layout,
separation: float = 10.0,
) -> dict:
# set positions
@cvanelteren
cvanelteren / test.json
Created September 29, 2022 12:57
visgraph test
{"directed": false, "multigraph": false, "graph": {"name": "Krackhardt Kite Social Network"}, "nodes": [{"id": 0}, {"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6}, {"id": 7}, {"id": 8}, {"id": 9}], "links": [{"source": 0, "target": 1}, {"source": 0, "target": 2}, {"source": 0, "target": 3}, {"source": 0, "target": 5}, {"source": 1, "target": 3}, {"source": 1, "target": 4}, {"source": 1, "target": 6}, {"source": 2, "target": 3}, {"source": 2, "target": 5}, {"source": 3, "target": 4}, {"source": 3, "target": 5}, {"source": 3, "target": 6}, {"source": 4, "target": 6}, {"source": 5, "target": 6}, {"source": 5, "target": 7}, {"source": 6, "target": 7}, {"source": 7, "target": 8}, {"source": 8, "target": 9}]}
@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)