def test_cmap_blending(self): self.composite.allocate('a') self.composite.allocate('b') self.composite.set('a', zorder=0, visible=True, array=self.array1, color=cm.Blues, clim=(0, 2)) self.composite.set('b', zorder=1, visible=True, array=self.array2, color=cm.Reds, clim=(0, 1)) # Determine expected result for each layer individually in the absence # of transparency expected_a = np.array([[cm.Blues(1.), cm.Blues(0.5)], [cm.Blues(0.), cm.Blues(0.)]]) expected_b = np.array([[cm.Reds(0.), cm.Reds(1.)], [cm.Reds(0.), cm.Reds(0.)]]) # If both layers have alpha=1, the top layer should be the only one visible assert_allclose(self.composite[...], expected_b) # If the top layer has alpha=0, the bottom layer should be the only one visible self.composite.set('b', alpha=0.) assert_allclose(self.composite[...], expected_a) # If the top layer has alpha=0.5, the result should be an equal blend of each self.composite.set('b', alpha=0.5) assert_allclose(self.composite[...], 0.5 * (expected_b + expected_a))
def figureCaRatio(ax1, ax2): stimlist = [ simDataPath + 'PSim_ConstrainUp_noGABAcontrol_16spinesp3tertdend1_81.8e-05TimeDelay0Mirror_0BranchOffset_0_', simDataPath + 'PSim_ConstrainUp_GABAAfast_tertdend1_8_0_16spinesp3tertdend1_81.8e-05TimeDelay0Mirror_0BranchOffset_0.1_', simDataPath + 'PSim_ConstrainUp_GABAAslow_tertdend1_8_0_16spinesp3tertdend1_81.8e-05TimeDelay0Mirror_0BranchOffset_0.1_', ] labels = ['Control', 'Fast GABA', 'Slow GABA'] colors = [ cm.gray(5 / 10.), cm.Reds(np.linspace(1, 0, 10))[1], cm.Reds(np.linspace(1, 0, 10))[4] ] ax = ax1 normdata = importGABA(stimlist, labels) handles = [] for i, key in enumerate(normdata): spy = normdata[key]['spy'] cay = normdata[key]['cay'] mspy = normdata[key]['mspy'] handle, = ax.plot(mspy[:, 0], mspy[:, 1], label='', marker='s', markersize=4, c=colors[i]) handles.append(handle) handle, = ax2.plot(cay[:, 0], cay[:, 1], label='', marker='o', c=colors[i], markersize=4, linestyle=':', alpha=.9) handles.append(handle) ax.legend([handles[i] for i in [0, 2, 4]], labels, title='Non-Stim Spine', frameon=True, fancybox=True, loc='upper left') ax2.legend([handles[i] for i in [1, 3, 5]], labels, title='Dendrite', frameon=True, fancybox=True, loc='upper left') format0(ax) ax.set_xlabel(u'Distance from Soma (µm)', labelpad=0) ax.set_ylabel('Peak $\it{[Ca^{2+}]}$ / Stim Spine Peak $\it{[Ca^{2+}]}$', labelpad=0) ax.set_xlim([20, 220]) ax.set_ylim([-.01, .36]) format1(ax2) ax2.set_xlabel(u'Distance from Soma (µm)', labelpad=0) ax2.set_xlim(ax.get_xlim()) ax2.set_ylim([-.01, .36]) return ax, normdata
def actions( location, action_type=None, result=None, team=None, label=None, labeltitle=None, color="white", ax=None, figsize=None, zoom=False, legloc="right", show=True, show_legend=True, ): ax = field(ax=ax, color=color, figsize=figsize, show=False) fig = plt.gcf() figsize, _ = fig.get_size_inches() arrowsize = math.sqrt(figsize) # SANITIZING INPUT location = np.asarray(location) if action_type is None: m, n = location.shape action_type = ["pass" for i in range(m)] if label is None: show_legend = False action_type = np.asarray(action_type) if team is None: team = ["Team X" for t in action_type] team = np.asarray(team) assert team.ndim == 1 if result is None: result = [1 for t in action_type] result = np.asarray(result) assert result.ndim == 1 if label is None: label = [t for t in action_type] label = np.asarray(label) lines = get_lines(label) if label is None: label = [[t] for t in action_type] label = np.asarray(label) if label.ndim == 1: label = label.reshape(-1, 1) assert label.ndim == 2 indexa = np.asarray([list(range(1, len(label) + 1))]).reshape(-1, 1) label = np.concatenate([indexa, label], axis=1) if labeltitle is not None: labeltitle = list(labeltitle) labeltitle.insert(0, "") labeltitle = [labeltitle] label = np.concatenate([labeltitle, label]) lines = get_lines(label) titleline = lines[0] plt.plot(np.NaN, np.NaN, "-", color="none", label=titleline) plt.plot(np.NaN, np.NaN, "-", color="none", label="-" * len(titleline)) lines = lines[1:] else: lines = get_lines(label) m, n = location.shape if n != 2 and n != 4: raise ValueError("Location must have 2 or 4 columns") if n == 2: loc_end = location.copy() loc_end[:-1, :] = loc_end[1:, :] location = np.concatenate([location, loc_end], axis=1) assert location.shape[1] == 4 text_offset = 3 if zoom: x = np.concatenate([location[:, 0], location[:, 2]]) y = np.concatenate([location[:, 1], location[:, 3]]) xmin = min(x) xmax = max(x) ymin = min(y) ymax = max(y) mx = (xmin + xmax) / 2 dx = (xmax - xmin) / 2 my = (ymin + ymax) / 2 dy = (ymax - ymin) / 2 if type(zoom) == bool: d = max(dx, dy) else: d = zoom text_offset = 0.07 * d zoompad = 5 xmin = max(mx - d, 0) - zoompad xmax = min(mx + d, spadl_config["length"]) + zoompad ax.set_xlim(xmin, xmax) ymin = max(my - d, 0) - zoompad ymax = min(my + d, spadl_config["width"]) + zoompad ax.set_ylim(ymin, ymax) h, w = fig.get_size_inches() h, w = xmax - xmin, ymax - ymin newh, neww = figsize, w / h * figsize fig.set_size_inches(newh, neww, forward=True) arrowsize = (w + h) / 2 / 105 * arrowsize eventmarkers = itertools.cycle(["s", "p", "h"]) event_types = set(action_type) eventmarkerdict = {"pass": "******"} for eventtype in event_types: if eventtype != "pass": eventmarkerdict[eventtype] = next(eventmarkers) markersize = figsize * 2 def get_color(type_name, te): home_team = team[0] if type_name == "dribble": return "black" elif te == home_team: return "blue" else: return "red" colors = np.array([get_color(ty, te) for ty, te in zip(action_type, team)]) blue_n = np.sum(colors == "blue") red_n = np.sum(colors == "red") blue_markers = iter(list(cm.Blues(np.linspace(0.1, 0.8, blue_n)))) red_markers = iter(list(cm.Reds(np.linspace(0.1, 0.8, red_n)))) cnt = 1 for ty, r, loc, color, line in zip(action_type, result, location, colors, lines): [sx, sy, ex, ey] = loc plt.text(sx + text_offset, sy, str(cnt)) cnt += 1 if color == "blue": c = next(blue_markers) elif color == "red": c = next(red_markers) else: c = "black" if ty == "dribble": ax.plot( [sx, ex], [sy, ey], color=c, linestyle="--", linewidth=2, label=line, zorder=zaction, ) else: ec = "black" if r else "red" m = eventmarkerdict[ty] ax.plot( sx, sy, linestyle="None", marker=m, markersize=markersize, label=line, color=c, mec=ec, zorder=zaction, ) if abs(sx - ex) > 1 or abs(sy - ey) > 1: ax.arrow( sx, sy, ex - sx, ey - sy, head_width=arrowsize, head_length=arrowsize, linewidth=1, fc=ec, ec=ec, length_includes_head=True, zorder=zaction, ) # leg = plt.legend(loc=9,prop={'family': 'monospace','size':12}) if show_legend: if legloc == "top": leg = plt.legend( bbox_to_anchor=(0.5, 1.05), loc="lower center", prop={"family": "monospace"}, ) elif legloc == "right": leg = plt.legend( bbox_to_anchor=(1.05, 0.5), loc="center left", prop={"family": "monospace"}, ) if show: plt.show()
N = int(paras[0]) # Distance along x-axis to edge of box from origin L = float(paras[1]) / 2. # Plot range lim = 1.1 * L #Number of data points dp = len(lines) # Define the colors to use in the plot, using the signs of the masses f = open(Signs, 'r') read = f.readline() f.close signs = [float(read.split()[i]) for i in xrange(N)] colors = [0 for i in xrange(N)] pos = cm.Blues(np.linspace(0, 1, N)) neg = cm.Reds(np.linspace(0, 1, N)) for i in xrange(N): if (signs[i] > 0): colors[i] = 'b' else: colors[i] = 'r' # Read data and make plots # Read coordinates into 2D list, plot with different color for each body # This should work automatically, with user only changing value of N x = [[0 for j in xrange(dp)] for i in xrange(N)] y = [[0 for j in xrange(dp)] for i in xrange(N)] z = [[0 for j in xrange(dp)] for i in xrange(N)] t = [0 for i in xrange(dp)] j = 0