%run talktools %matplotlib inline import numpy as np import matplotlib.pyplot as plt np.random.seed(0) x, y = np.random.normal(size=(2, 100)) s, c = np.random.random(size=(2, 100)) def draw_scatter(size=100, cmap='jet', alpha=1.0): fig, ax = plt.subplots(figsize=(8, 6)) points = ax.scatter(x, y, s=size*s, c=c, alpha=alpha, cmap=cmap) fig.colorbar(points, ax=ax) return fig draw_scatter(size=100, cmap='jet', alpha=1.0); from IPython.html.widgets import interact colormaps = sorted(m for m in plt.cm.datad if not m.endswith("_r")) interact(draw_scatter, size=[0, 2000], alpha=[0.0, 1.0], cmap=colormaps); import networkx as nx def random_lobster(n, m, k, p): return nx.random_lobster(n, p, p / m) def powerlaw_cluster(n, m, k, p): return nx.powerlaw_cluster_graph(n, m, p) def erdos_renyi(n, m, k, p): return nx.erdos_renyi_graph(n, p) def newman_watts_strogatz(n, m, k, p): return nx.newman_watts_strogatz_graph(n, k, p) def plot_random_graph(n, m, k, p, generator): g = generator(n, m, k, p) nx.draw(g) plt.show() interact(plot_random_graph, n=(2,30), m=(1,10), k=(1,10), p=(0.0, 1.0, 0.001), generator={'lobster': random_lobster, 'power law': powerlaw_cluster, 'Newman-Watts-Strogatz': newman_watts_strogatz, u'Erdős-Rényi': erdos_renyi, }); import numpy as np from scipy import integrate from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib.colors import cnames from matplotlib import animation def solve_lorenz(N=10, angle=0.0, max_time=4.0, sigma=10.0, beta=8./3, rho=28.0): def lorenz_deriv((x, y, z), t0, sigma=sigma, beta=beta, rho=rho): """Compute the time-derivative of a Lorentz system.""" return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z] # Choose random starting points, uniformly distributed from -15 to 15 np.random.seed(1) x0 = -15 + 30 * np.random.random((N, 3)) # Solve for the trajectories t = np.linspace(0, max_time, int(250*max_time)) x_t = np.asarray([integrate.odeint(lorenz_deriv, x0i, t) for x0i in x0]) # choose a different color for each trajectory colors = plt.cm.jet(np.linspace(0, 1, N)) # plot the results fig = plt.figure() ax = fig.add_axes([0, 0, 1, 1], projection='3d') ax.axis('off') # prepare the axes limits ax.set_xlim((-25, 25)) ax.set_ylim((-35, 35)) ax.set_zlim((5, 55)) for i in range(N): x, y, z = x_t[i,:,:].T lines = ax.plot(x, y, z, '-', c=colors[i]) plt.setp(lines, linewidth=2) ax.view_init(30, angle) plt.show() return t, x_t t, x_t = solve_lorenz() from IPython.html.widgets import interactive w = interactive(solve_lorenz, angle=(0.,360.), N=(0,50), sigma=(0.0,50.0), rho=(0.0,50.0)) display(w) w.result