def make_illustration_snapshot(): fig = plt.figure() ax = fig.gca() model = vicsek_model_factory(model='angular', n=200, L=100.0, eta=0.2, v_0=0.5) for _ in range(100): model.iterate() ejm_rcparams.set_pretty_plots(use_latex=True, use_pgf=True) ejm_rcparams.prettify_axes(ax) ax.set_xlim(-model.L_half, model.L_half) ax.set_ylim(-model.L_half, model.L_half) ax.set_aspect('equal') i_source = np.argmin(np.sum(np.square(model.r), axis=1)) r_i = model.r[i_source] c = plt.Circle(r_i, radius=model.r_v, fill=False, edgecolor='red') ax.add_patch(c) colors = np.zeros([model.n]) colors[i_source] = 1.0 i_neighbs = model._neighbs(i_source) for i_neighb in i_neighbs: colors[i_neighb] = 0.5 s = 2.0 ax.quiver(model.r[:, 0], model.r[:, 1], s * model.L * model.u[:, 0], s * model.L * model.u[:, 1], colors, pivot='mid', edgecolor='none') ax.axis('off') plt.savefig('vicsek_snapshot_demo.pdf', bbox_inches='tight', transparent=True)
def make_disordered_snapshot(): model = vicsek_model_factory(model='angular', n=100, L=100.0, eta=0.8, v_0=0.5) for _ in range(100): model.iterate() fig = plt.figure() ax = fig.gca() ejm_rcparams.set_pretty_plots(use_latex=True, use_pgf=True) ejm_rcparams.prettify_axes(ax) ax.set_xlim(-model.L_half, model.L_half) ax.set_ylim(-model.L_half, model.L_half) ax.set_aspect('equal') s = 2.0 ax.quiver(model.r[:, 0], model.r[:, 1], s * model.L * model.u[:, 0], s * model.L * model.u[:, 1], pivot='mid', edgecolor='none') ax.axis('off') plt.savefig('vicsek_snapshot_disordered.pdf', bbox_inches='tight', transparent=True)
import matplotlib.pyplot as plt import dataset import paths from ciabatta import ejm_rcparams save_flag = True use_latex = save_flag use_pgf = True ejm_rcparams.set_pretty_plots(use_latex, use_pgf) dr = 0.7 fig = plt.figure(figsize=(12, 12 * ejm_rcparams.golden_ratio)) ax = fig.add_subplot(111) ejm_rcparams.prettify_axes(ax) def plot_rdf(ax, dset_path, smooth): dset = dataset.get_dset(dset_path) rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr) vp, vp_err = dset.get_vp() R = dset.R if use_latex: label = r"$\SI{" + "{:.3g}".format(R) + r"}{\um}$, " + r"$\SI{" + "{:.2g}".format(vp) + r"}{\percent}$" else: label = r"$" + "{:.3g}".format(R) + r"\mu m$, $" + "{:.2g}".format(vp) + r"\%$" if smooth: label += r", Smooth swimming"
import matplotlib.pyplot as plt from ciabatta import ejm_rcparams from colors import * from dataset import pickle_load import numpy as np import paths save_flag = True use_latex = save_flag use_pgf = True ejm_rcparams.set_pretty_plots(use_latex, use_pgf) fig = plt.figure(figsize=(12, 12 * ejm_rcparams.golden_ratio)) ax = fig.add_subplot(111) ejm_rcparams.prettify_axes(ax) dr = 0.7 def get_stat(pickle_path, alg): superset = pickle_load(pickle_path) eta_0, eta_0_err = superset.get_eta_0() f_peak, f_peak_err = superset.get_f_peak(alg, dr) return eta_0, eta_0_err, f_peak, f_peak_err eta_0, eta_0_err, f_peak, f_peak_err = get_stat(paths.exp_pickle_path, 'mean') ax.errorbar(eta_0, f_peak, xerr=eta_0_err, yerr=f_peak_err, ls='none', label=r'Method A', c=color_exp) eta_0, eta_0_err, f_peak, f_peak_err = get_stat(paths.exp_pickle_path, 'median')
from __future__ import print_function, division import numpy as np import scipy.stats import matplotlib as mpl import matplotlib.pyplot as plt import sklearn from sklearn.cluster import KMeans from ciabatta import ejm_rcparams ejm_rcparams.set_pretty_plots(use_latex=False, use_pgf=True) def get_data(): d = np.loadtxt('exercise.txt', delimiter=',').T inds = np.arange(d.shape[1]) return inds, d def remove_single_point_spikes(d): d_filter = d.copy() for i in range(1, d.shape[0] - 1): if (d[i] != d[i - 1]) and (d[i - 1] == d[i + 1]): d_filter[i] = d[i - 1] return d_filter def denoise_data(d): d_denoise = d.copy() for sample in d_denoise: sample[:] = remove_single_point_spikes(sample) return d_denoise
from __future__ import print_function import matplotlib.pyplot as plt from runner import get_filenames, filename_to_model from ciabatta import pack, ejm_rcparams from fipy import MatplotlibViewer, MatplotlibVectorViewer import numpy as np ejm_rcparams.set_pretty_plots(False, False) def plot_coarse(dirname): filenames = get_filenames(dirname) model_0 = filename_to_model(filenames[0]) plt.show() plt.ion() fig, axs = plt.subplots(2, 2, sharex=True, sharey=True) axs = axs.flatten() ax_rho, ax_p, ax_food, ax_food_grad = axs for ax in axs: ax.set_xlim(-model_0.L[0] / 2.0, model_0.L[0] / 2.0) ax.set_ylim(-model_0.L[1] / 2.0, model_0.L[1] / 2.0) view_args = {'xmin': -model_0.L[0] / 2.0, 'xmax': model_0.L[0] / 2.0, 'ymin': -model_0.L[1] / 2.0, 'ymax': model_0.L[1] / 2.0, 'cmap': ejm_rcparams.reds}