Skip to content

Instantly share code, notes, and snippets.

@AlexanderFabisch
Last active August 29, 2015 14:05
Show Gist options
  • Save AlexanderFabisch/5855826dc8d7c80746ad to your computer and use it in GitHub Desktop.
Save AlexanderFabisch/5855826dc8d7c80746ad to your computer and use it in GitHub Desktop.
Python tricks

Generate a 2D grid of shape (n_samples, 2)

np.vstack(map(np.ravel, np.meshgrid(x, y))).T

Cycle over line styles (source)

import matplotlib.pyplot as plt
from itertools import cycle
lines = ["-", "--", "-.", ":"]
linecycler = cycle(lines)
plt.figure()
for i in range(10):
    x = range(i,i+10)
    plt.plot(range(10),x,next(linecycler))
plt.show()

Matplotlib 3d plots (source)

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

Numpy performance tips:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment