Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaohanyu/910d4747fe191d8039858c60b9715b07 to your computer and use it in GitHub Desktop.
Save xiaohanyu/910d4747fe191d8039858c60b9715b07 to your computer and use it in GitHub Desktop.
Org-mode's org-babel, literate programming with python and latex.
import matplotlib.pyplot as plt
import numpy as np

L = 6
x = np.linspace(0, L)
ncolors = len(plt.rcParams['axes.color_cycle'])
shift = np.linspace(0, L, ncolors, endpoint=False)
for s in shift:
    plt.plot(x, np.sin(x + s), 'o-')
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.title('title')

plt.show()

plot2.png

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)

plt.show()

plot3.png

datexyz
<2016-06-15 Wed>111
<2016-06-16 Thu>222
<2016-06-17 Fri>433
<2016-06-18 Sat>844
<2016-06-19 Sun>16530
<2016-06-20 Mon>32640
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
%matplotlib inline

df = pd.DataFrame(table[1:], columns=table[0])
df.plot()

plot.png

def foo(x):
    return x + 9

[foo(x) + 7 for x in range(7)]
16171819202122
def foo(x):
    return x + 9

[foo(x) + 7 for x in range(7)]
\LaTeX
\LaTeX
% Define block styles
\usetikzlibrary{shapes,arrows}
\tikzstyle{astate} = [circle, draw, text centered, font=\footnotesize, fill=blue!25]
\tikzstyle{rstate} = [circle, draw, text centered, font=\footnotesize, fill=red!25]

\begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto, node distance=2.8cm, semithick]
  \node [astate] (1) at (0,0) {1};
  \node [astate] (2) at (1,0) {2};
  \node [rstate] (3) at (2,0) {3};
  \path (1) edge [bend left] node {b} (2)
        (2) edge node {b} (3)
        (2) edge [bend left] node {a} (1)
        (3) edge [loop above] node {(a, b)} (3);
\end{tikzpicture}
% Define block styles
\usetikzlibrary{shapes,arrows}
\tikzstyle{astate} = [circle, draw, text centered, font=\footnotesize, fill=blue!25]
\tikzstyle{rstate} = [circle, draw, text centered, font=\footnotesize, fill=red!25]

\begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto, node distance=2.8cm, semithick]
  \node [astate] (1) at (0,0) {1};
  \node [astate] (2) at (1,0) {2};
  \node [rstate] (3) at (2,0) {3};
  \path (1) edge [bend left] node {b} (2)
        (2) edge node {b} (3)
        (2) edge [bend left] node {a} (1)
        (3) edge [loop above] node {(a, b)} (3);
\end{tikzpicture}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment