Skip to content

Instantly share code, notes, and snippets.

@windstriver
windstriver / matplotlib2pdf.py
Created January 19, 2017 12:58
A python script to save matplotlib plot to pdf file.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
x = np.random.randn(1000)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.hist(x, 100)
@windstriver
windstriver / interpolationUDF.c
Created December 28, 2016 10:52
ANSYS Fluent UFD to interpolate flow variable (p, u, v, w) of arbitrary point based on the cell centroid variable.
#include "udf.h"
#define MAXPOINTS 5000
#define NSCALARS (1+ND_ND)
float coords[MAXPOINTS][ND_ND+1];
float values[MAXPOINTS][NSCALARS+ND_ND];
int total_count;
int total_points_found = 0;
@windstriver
windstriver / test.py
Created August 5, 2016 07:51
Test function in functional analysis.
import numpy as np
import matplotlib.pylab as plt
def phi(x):
y = np.zeros((len(x), ))
index = np.absolute(x) < 1
y[index] = np.exp(1/(x[index]**2-1))
return y
@windstriver
windstriver / signpost.tex
Created June 29, 2016 11:26
TikZ example, mechanical diagram.
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
% Vector Styles
\tikzstyle{load}=[ultra thick,-latex]
\tikzstyle{stress}=[-latex]
\tikzstyle{dim}=[latex-latex]
\tikzstyle{axis}=[-latex,black!55]
% Drawing Views
@windstriver
windstriver / invcum.dat
Created June 28, 2016 02:24
PGFPLOTS: plot external data
x_0 f(x)
$flags auto[subscript]:8 auto[subscript]:8
3.16693000e-05 -4.00001451e+00
1.00816962e-03 -3.08781504e+00
1.98466995e-03 -2.88058811e+00
2.96117027e-03 -2.75205040e+00
3.93767059e-03 -2.65736805e+00
4.91417091e-03 -2.58181091e+00
5.89067124e-03 -2.51862689e+00
6.86717156e-03 -2.46413745e+00
@windstriver
windstriver / pgfplotsexample.tex
Created June 28, 2016 02:10
PGFPLOTS: simple example
\documentclass[a4paper]{article}
% for dvipdfm:
%\def\pgfsysdriver{pgfsys-dvipdfm.def}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}% <-- moves axis labels near ticklabels (respects tick label widths)
\begin{document}
\begin{figure}
\centering
@windstriver
windstriver / fun.py
Created June 28, 2016 01:38
Plot complex function using TikZ & Python
import numpy as np
def coth(x):
return np.cosh(x)/np.sinh(x)
def brilloutin(J, x):
if x == 0:
return 0
else:
return (2*J+1)/(2*J)*coth((2*J+1)/(2*J)*x) - 1/(2*J)*coth(1/(2*J)*x)
@windstriver
windstriver / brillouin-function.tex
Created June 27, 2016 12:06
Example: Plot of the Brillouin Function
% Brillouin Function
% Author: Mark Wibrow
\documentclass[tikz,border=10pt]{standalone}
\usepackage{amsmath}
\usetikzlibrary{arrows.meta}
\directlua{
function coth (i)
return math.cosh(i) / math.sinh(i)
end
@windstriver
windstriver / parametric_plot_with_tikz.tex
Created August 30, 2015 01:32
An example of parametric plot using TikZ from *TikZ & PGF Manual*.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=2]
\draw[gray,very thin] (-1.9,-1.9) grid (2.9,3.9)
[step=0.25cm] (-1,-1) grid (1,1);
\draw[blue] (1,-2.1) -- (1,4.1); % asymptote
\draw[->] (-2,0) -- (3,0) node[right] {$x(t)$};
@windstriver
windstriver / tikz_datavisualization.tex
Created August 30, 2015 00:49
Data visualization example from TikZ & PGF Manual
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization [scientific axes=clean]
[