Skip to content

Instantly share code, notes, and snippets.

@nicoguaro
nicoguaro / data.tsv
Created Aug 28, 2015
Vertical barchart using D3 and reading data from a tab separated fiel.
View data.tsv
name value
Locke 4
Reyes 8
Ford 12
Jarrah 16
Shephard 23
Kwon 42
@nicoguaro
nicoguaro / index.html
Created Aug 28, 2015
Ashby chart showing Young Modulus vs density for some materials. It was done using D3
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<!--
Example based on http://bl.ocks.org/weiglemc/6185069
-->
<style>
.circ {
fill: steelblue;
@nicoguaro
nicoguaro / plot_guy.py
Last active Aug 29, 2015
Plot stick men.
View plot_guy.py
import matplotlib.pyplot as plt
import numpy as np
def plot_guy(x, y, frown=False, **plot_args):
"""Plot a stick man of 2 units wide and 6 units tall.
http://nbviewer.ipython.org/gist/theandygross/4544012
"""
an = np.array(np.linspace(0,2*np.pi,100))
head, = plt.plot(np.cos(an)+x, np.sin(an)+y + 5, **plot_args)
View butterfly_curves.py
"""
Plot multiple butterfly curves.
"""
import numpy as np
import matplotlib.pyplot as plt
def curve(turns, npts):
t = np.linspace(0, 2*turns*np.pi, npts)
x = np.sin(t)*(np.exp(np.cos(t))- 2*np.cos(4*t) - np.sin(t/12)**5)
@nicoguaro
nicoguaro / example_layered_elastic.py
Created Apr 20, 2015
Dispersion curves for multilayer elastic materials using Trasfer Matrix Method and Bloch theorem.
View example_layered_elastic.py
# -*- coding: utf-8 -*-
"""
Wave propagation in layered elastic media.
@author: Nicolas Guarin-Zapata
@email: nguarin@purdue.edu
"""
import matplotlib.pyplot as plt
from matplotlib import rcParams
from layered_elastic import *
@nicoguaro
nicoguaro / bilinear_map.ipynb
Last active Aug 29, 2015
Bilinear map inversion (analytically)
View bilinear_map.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nicoguaro
nicoguaro / hausdorff.py
Last active Aug 29, 2015
Calculate two-side Hausdorff distance between two sets using a brute force approach.
View hausdorff.py
# -*- coding: utf-8 -*-
"""
Calculate two-side Hausdorff distance between two sets using a brute
force approach.
References
[1] http://en.wikipedia.org/wiki/Hausdorff_distance
@author: Nicolas Guarin-Zapata
"""
@nicoguaro
nicoguaro / parallel_proj.py
Last active Aug 29, 2015
Snippets relted to Paraview
View parallel_proj.py
"""
Set projection to parallel in Paraview
In Paraview 4.3 the default is perspective projection.
"""
camera = GetActiveCamera ()
camera. SetParallelProjection (True)
@nicoguaro
nicoguaro / eval_fun.py
Created May 11, 2015
Evaluate a function with variable number of parameters.
View eval_fun.py
def eval_fun(f, **args):
""" (str, dict) -> object
f: Function as string.
args: dictionary with arbitrary variables.
Use arbitrary args in **args to eval general functions.
Examples:
>> eval_fun('x**2',x=5)
25
>> eval_fun('x*y', x=3, y=2)
6
@nicoguaro
nicoguaro / plot_mesh.py
Created May 11, 2015
Plot a (finite element) mesh formed by 8 node (serendipity) elements.
View plot_mesh.py
from numpy import array
from matplotlib import pyplot as plt
def plot_msh(pts, els, shw_pts=True, shw_els=True,
pts_text=False, els_text=False):
"""
Plot a mesh of 8 nodes (serendipity) elements.
Parameters
----------