def print_current(merged, prefix=""): a1, d1 = merged[prefix + "am"].values, merged[prefix + "dm"].values a2, d2 = merged["ae"].values, merged["de"].values ax = plt.gca() segs = [] widths = [] scale = 3 width_scale = 1000 a1 = np.array(a1) d1 = np.array(d1) a2 = np.array(a2) d2 = np.array(d2) for i, a in enumerate(a1): al = (a1[i] - a2[i]) dl = (d1[i] - d2[i]) segs.append(((a1[i] + scale * al, d1[i] + scale * dl), (a2[i] - scale * al, d2[i] - scale * dl))) widths.append(np.sqrt(al * al + dl * dl) * width_scale) ln_coll = LineCollection(segs, color="black", linewidth=widths) ln_coll.set_antialiased(True) ax.add_collection(ln_coll) ax.axis("equal") ax.invert_xaxis() plt.legend()
def plot(ax, x, y, time, sim_type): assert(len(x) == len(y) == len(time)) l = len(time) if use_hf_coloration: time_to_grayscale = 0.8 / 23.6 # for HF coloring else: time_to_grayscale = 0.8 / time[l-1] colors = [] for i in range(l-1): if use_hf_coloration: color = get_hf_color(time[i]) # time[] is really HF else: g = 0.8 - (time[i] * time_to_grayscale)**2.0 if sim_type == 'driven': color = (g, 1.0, g, 0.8) else: color = (g, g, 1.0, 1.0) colors.append(color) points = zip(x,y) segments = zip(points[:-1], points[1:]) lc = LineCollection(segments, colors=colors) lc.set_alpha(1.0) lc.set_linewidth(1.0) lc.set_antialiased(True) ax.add_collection(lc) if use_hf_coloration: end_points.append((x[l-1], y[l-1], get_hf_color(time[l-1]))) else: end_points.append((x[l-1], y[l-1], COLOR[sim_type]))
def plot(ax, x, y, time, sim_type): assert (len(x) == len(y) == len(time)) l = len(time) if use_hf_coloration: time_to_grayscale = 0.8 / 23.6 # for HF coloring else: time_to_grayscale = 0.8 / time[l - 1] colors = [] for i in range(l - 1): if use_hf_coloration: color = get_hf_color(time[i]) # time[] is really HF else: g = 0.8 - (time[i] * time_to_grayscale)**2.0 if sim_type == 'driven': color = (g, 1.0, g, 0.8) else: color = (g, g, 1.0, 1.0) colors.append(color) points = zip(x, y) segments = zip(points[:-1], points[1:]) lc = LineCollection(segments, colors=colors) lc.set_alpha(1.0) lc.set_linewidth(1.0) lc.set_antialiased(True) ax.add_collection(lc) if use_hf_coloration: end_points.append((x[l - 1], y[l - 1], get_hf_color(time[l - 1]))) else: end_points.append((x[l - 1], y[l - 1], COLOR[sim_type]))
def animation(j): global T, dT_xx if j > 0: dT_xx = dd_x(d_x(T)) # dT_xx = d(T) m = a * max(dT_xx.max(), abs(dT_xx.min())) * dt if max(m, dx_max) > dx_max: time = 0 while time < dt: dT_xx = dd_x(d_x(T)) # dT_xx = d(T) m = a * max(dT_xx.max(), abs(dT_xx.min())) * dt dt_tempo = dx_max / m T += a * dT_xx * dt_tempo time += dt_tempo else: T += a * dT_xx * dt ax.clear() points = np.array([X, T]).T.reshape(-1, 1, 2) segments = np.concatenate([points[:-2], points[2:]], axis=1) lc = LineCollection(segments, cmap='plasma', norm=norm) lc.set_array(0.5 * (T[:-2] + T[2:])) lc.set_linewidth(1) lc.set_antialiased(True) line = ax.add_collection(lc) # fig.colorbar(line, ax=ax) plt.ylim(T_min - delta, T_max + delta) plt.xlim(x_0, x_f)
def get_solid_line(y, c_map, width, color, onecolor=None, limits=None): points = np.array([y[3, :], y[2, :]]).T.reshape(-1, 1, 2) segments = np.concatenate([points[:-1], points[1:]], axis=1) if onecolor: color = np.array([onecolor] * len(y[0, :])) lc = LineCollection(segments, colors=color) else: if limits: norm = plt.Normalize(limits[0], limits[1]) lc = LineCollection(segments, cmap=c_map, norm=norm) else: lc = LineCollection(segments, cmap=c_map) lc.set_array(color) lc.set_linewidth(width) #lc.set_joinstyle('bevel') lc.set_snap(False) lc.set_capstyle('round') #projecting lc.set_antialiased(True) return lc
def plotter(choice, numNeurons, numTimeSteps, maxNeurons, maxTimeSteps, reverse, numInputNeurons, colorNeurons, redStart, redEnd, greenStart, greenEnd, blueStart, blueEnd, eatNeuron, mateNeuron, fightNeuron, moveNeuron, yawNeuron, label, behaviorLabels, inputLabels): rhythm_file = open_file(choice, "r") line = next_line(rhythm_file) line = next_line(rhythm_file) figwidth = 12.0 figheight = 8.0 fig = pylab.figure(figsize=(figwidth, figheight)) ax = fig.add_subplot(111) ax.set_xlim(0.5, maxTimeSteps + 0.5) ax.set_ylim(maxNeurons - 0.5, -0.5) pylab.title(label) pylab.ylabel('Neuron Index') pylab.xlabel('Time Step') linewidth = 0.715 * fig.get_figwidth() * fig.get_dpi() / maxTimeSteps for time in range(numTimeSteps): x = [] y = [] colors = [] for neuron in range(numNeurons): activ = line.split() x.append(time + 1) y.append(neuron - 0.5) activation = float(activ[1]) if reverse: activation = 1.0 - activation if colorNeurons: if neuron in range(redStart, redEnd + 1): colors.append((activation, activation * ALT_COLOR_MAX, activation * ALT_COLOR_MAX, 1.0)) elif neuron in range(greenStart, greenEnd + 1): colors.append((activation * ALT_COLOR_MAX, activation, activation * ALT_COLOR_MAX, 1.0)) elif neuron in range(blueStart, blueEnd + 1): colors.append( (activation * ALT_COLOR_MAX, activation * ALT_COLOR_MAX, activation, 1.0)) elif neuron == eatNeuron: colors.append((activation * ALT_COLOR_MAX, activation, activation * ALT_COLOR_MAX, 1.0)) elif neuron == mateNeuron: colors.append( (activation * ALT_COLOR_MAX, activation * ALT_COLOR_MAX, activation, 1.0)) elif neuron == fightNeuron: colors.append((activation, activation * ALT_COLOR_MAX, activation * ALT_COLOR_MAX, 1.0)) elif neuron == yawNeuron: colors.append((activation, activation, activation * ALT_COLOR_MAX, 1.0)) else: colors.append((activation, activation, activation, 1.0)) else: colors.append((activation, activation, activation, 1.0)) line = next_line(rhythm_file) x.append(time + 1) y.append(neuron + 0.5) colors.append((activation, activation, activation, 1.0)) points = zip(x, y) segments = zip(points[:-1], points[1:]) lc = LineCollection(segments, colors=colors) lc.set_alpha(1.0) lc.set_linewidth(linewidth) lc.set_antialiased(False) ax.add_collection(lc) rhythm_file.close() if behaviorLabels: matplotlib.pyplot.text(maxTimeSteps + 1.5, eatNeuron, "Eat", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps + 1.5, mateNeuron, "Mate", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps + 1.5, fightNeuron, "Fight", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps + 1.5, moveNeuron, "Move", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps + 1.5, yawNeuron, "Turn", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps + 1.5, yawNeuron + 1, "Light", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps + 1.5, yawNeuron + 2, "Focus", weight="ultralight", size="small", va="center") if inputLabels: matplotlib.pyplot.text(maxTimeSteps + 1.5, 0, "Random", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps + 1.5, 1, "Health", weight="ultralight", size="small", va="center") for neuron in range(redStart, redEnd + 1): matplotlib.pyplot.text(maxTimeSteps + 1.5, neuron, "R", weight="ultralight", size="small", va="center") for neuron in range(greenStart, greenEnd + 1): matplotlib.pyplot.text(maxTimeSteps + 1.5, neuron, "G", weight="ultralight", size="small", va="center") for neuron in range(blueStart, blueEnd + 1): matplotlib.pyplot.text(maxTimeSteps + 1.5, neuron, "B", weight="ultralight", size="small", va="center")
def plotter(choice, numNeurons, numTimeSteps, maxNeurons, maxTimeSteps, reverse, numInputNeurons, colorNeurons, redStart, redEnd, greenStart, greenEnd, blueStart, blueEnd, eatNeuron, mateNeuron, fightNeuron, moveNeuron, yawNeuron, label, behaviorLabels, inputLabels): rhythm_file = open_file(choice, "r") line = next_line(rhythm_file) line = next_line(rhythm_file) figwidth = 12.0 figheight = 8.0 fig = pylab.figure(figsize=(figwidth,figheight)) ax = fig.add_subplot(111) ax.set_xlim(0.5, maxTimeSteps+0.5) ax.set_ylim(maxNeurons-0.5, -0.5) pylab.title(label) pylab.ylabel('Neuron Index') pylab.xlabel('Time Step') linewidth = 0.715 * fig.get_figwidth() * fig.get_dpi() / maxTimeSteps for time in range(numTimeSteps): x = [] y = [] colors = [] for neuron in range(numNeurons): activ = line.split() x.append(time+1) y.append(neuron-0.5) activation = float(activ[1]) if reverse: activation = 1.0 - activation if colorNeurons: if neuron in range(redStart, redEnd+1): colors.append((activation, activation*ALT_COLOR_MAX, activation*ALT_COLOR_MAX, 1.0)) elif neuron in range(greenStart, greenEnd+1): colors.append((activation*ALT_COLOR_MAX, activation, activation*ALT_COLOR_MAX, 1.0)) elif neuron in range(blueStart, blueEnd+1): colors.append((activation*ALT_COLOR_MAX, activation*ALT_COLOR_MAX, activation, 1.0)) elif neuron == eatNeuron: colors.append((activation*ALT_COLOR_MAX, activation, activation*ALT_COLOR_MAX, 1.0)) elif neuron == mateNeuron: colors.append((activation*ALT_COLOR_MAX, activation*ALT_COLOR_MAX, activation, 1.0)) elif neuron == fightNeuron: colors.append((activation, activation*ALT_COLOR_MAX, activation*ALT_COLOR_MAX, 1.0)) elif neuron == yawNeuron: colors.append((activation, activation, activation*ALT_COLOR_MAX, 1.0)) else: colors.append((activation, activation, activation, 1.0)) else: colors.append((activation, activation, activation, 1.0)) line = next_line(rhythm_file) x.append(time+1) y.append(neuron+0.5) colors.append((activation, activation, activation, 1.0)) points = zip(x, y) segments = zip(points[:-1], points[1:]) lc = LineCollection(segments, colors=colors) lc.set_alpha(1.0) lc.set_linewidth(linewidth) lc.set_antialiased(False) ax.add_collection(lc) rhythm_file.close() if behaviorLabels: matplotlib.pyplot.text(maxTimeSteps+1.5, eatNeuron, "Eat", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps+1.5, mateNeuron, "Mate", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps+1.5, fightNeuron, "Fight", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps+1.5, moveNeuron, "Move", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps+1.5, yawNeuron, "Turn", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps+1.5, yawNeuron+1, "Light", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps+1.5, yawNeuron+2, "Focus", weight="ultralight", size="small", va="center") if inputLabels: matplotlib.pyplot.text(maxTimeSteps+1.5, 0, "Random", weight="ultralight", size="small", va="center") matplotlib.pyplot.text(maxTimeSteps+1.5, 1, "Health", weight="ultralight", size="small", va="center") for neuron in range(redStart, redEnd+1): matplotlib.pyplot.text(maxTimeSteps+1.5, neuron, "R", weight="ultralight", size="small", va="center") for neuron in range(greenStart, greenEnd+1): matplotlib.pyplot.text(maxTimeSteps+1.5, neuron, "G", weight="ultralight", size="small", va="center") for neuron in range(blueStart, blueEnd+1): matplotlib.pyplot.text(maxTimeSteps+1.5, neuron, "B", weight="ultralight", size="small", va="center")