def gen_collection(self, ax): return mplc.CircleCollection(transOffset=ax.transData, offsets=self.offsets, sizes=self.sizes, edgecolor=self.edgecolor, facecolor=self.facecolor, zorder=self.zorder)
def _draw_png_matplotlib( X, I, J, filepath, noderadius=0.2, linkwidth=0.05, width=1000, border=50, nodeopacity=1, linkopacity=1, ): import matplotlib.pyplot as plt import matplotlib.collections as mc fig = plt.figure(figsize=(width, width)) ax = plt.axes() ax.set_xlim(min(X[:, 0]), max(X[:, 0])) ax.set_ylim(min(X[:, 1]), max(X[:, 1])) ax.axis("off") ax.set_aspect("equal", "box") # convert input data widths to display coordinates x_display_min, y_display_min = ax.transData.inverted().transform((0, 0)) noderadius_disp, linkwidth_disp = ax.transData.transform( (x_display_min + noderadius, y_display_min + linkwidth)) links = zip((X[i] for i in I), (X[j] for j in J)) lc = mc.LineCollection(links, linewidths=linkwidth_disp, colors=(0, 0, 0, linkopacity)) ax.add_collection(lc) cc = mc.CircleCollection( np.full(len(X), noderadius_disp * noderadius_disp), offsets=X, transOffset=ax.transData, linewidths=0, facecolors=(0, 0, 0, nodeopacity), ) ax.add_collection(cc) border_data, _ = ax.transLimits.transform((border / width, 0)) ax.set_xlim( min(X[:, 0]) - noderadius - border_data, max(X[:, 0]) + noderadius + border_data) ax.set_ylim( min(X[:, 1]) - noderadius - border_data, max(X[:, 1]) + noderadius + border_data) fig.savefig( filepath, dpi=1, bbox_inches="tight", format="png", transparent=True, origin="upper", )
def test_set_offsets_late(): identity = mtransforms.IdentityTransform() sizes = [2] null = mcollections.CircleCollection(sizes=sizes) init = mcollections.CircleCollection(sizes=sizes, offsets=(10, 10)) late = mcollections.CircleCollection(sizes=sizes) late.set_offsets((10, 10)) # Bbox.__eq__ doesn't compare bounds null_bounds = null.get_datalim(identity).bounds init_bounds = init.get_datalim(identity).bounds late_bounds = late.get_datalim(identity).bounds # offsets and transform are applied when set after initialization assert null_bounds != init_bounds assert init_bounds == late_bounds
def LoadPlotandSave(filename, unknown=False, flip=False, legend=False): a = np.load(filename) newfilename = filename recon = a['ReconstructedObject'] recon = recon[4:251, 4:251] recon_sorted = recon.copy().flatten() recon_sorted.sort() recon[recon > recon_sorted[-100]] = recon_sorted[-100] recon = np.fliplr(recon) cmaps = ['inferno'] i = 0 plt.imshow(recon**.5, cmap=cmaps[i]) plt.show() imsave(newfilename[:-4] + '_Object.png', recon, cmap=cmaps[i]) if unknown: Trajectory = a['Trajectory'] print('Test') W_np = a['W_np'] xpos = a['xpos'] zpos = a['zpos'] W_np_onehot = np.zeros((W_np.shape[0], 33 * 33)) for i in range(W_np.shape[0]): W_np_onehot[i, np.argmax(W_np[i])] = 1 W_np_onehot = np.reshape(W_np_onehot, (W_np.shape[0], 33, 33)) W_np_zs = np.array( [np.nonzero(W_np_onehot[i])[0] for i in range(W_np.shape[0])]) W_np_xs = np.array( [np.nonzero(W_np_onehot[i])[1] for i in range(W_np.shape[0])]) if flip: W_np_xs = 32 - W_np_xs import matplotlib.collections as collections fig = plt.figure(num=None, figsize=(4, 4), dpi=200, facecolor='w', edgecolor='k') ax = fig.add_subplot(1, 1, 1) gt_call = plt.scatter(-zpos, xpos, s=10, c=(0, 0, 0)) for i in range(W_np.shape[0]): min_alpha = .2 max_alpha = .8 alpha = min_alpha + (max_alpha - min_alpha) * i / W_np.shape[0] c = ((1 - i / W_np.shape[0]), 0, (i / W_np.shape[0]), alpha) if i == 0: init_call = ax.scatter(-W_np_zs[i] / 32. * .15, W_np_xs[i] / 32., s=100, c=c) #, alpha=alpha) else: final_call = ax.scatter(-W_np_zs[i] / 32. * .15, W_np_xs[i] / 32., s=100, c=c) #, alpha=alpha) alpha_start = min_alpha alpha_mid = min_alpha + (max_alpha - min_alpha) * np.floor( W_np.shape[0] / 2) / W_np.shape[0] alpha_end = min_alpha + (max_alpha - min_alpha) * (W_np.shape[0] - 1) / W_np.shape[0] c_start = ((1 - 0 / W_np.shape[0]), 0, (0 / W_np.shape[0]), alpha_start) c_mid = ((1 - np.floor(W_np.shape[0] / 2) / W_np.shape[0]), 0, np.floor(W_np.shape[0] / 2) / W_np.shape[0], alpha_mid) c_end = ((1 - (W_np.shape[0] - 1) / W_np.shape[0]), 0, ((W_np.shape[0] - 1) / W_np.shape[0]), alpha_end) circles = collections.CircleCollection( sizes=[100, 100, 100], facecolors=[c_start, c_mid, c_end]) circles.set_alpha(.5) frame1 = plt.gca() frame1.axes.get_xaxis().set_visible(False) frame1.axes.get_yaxis().set_visible(False) plt.savefig(newfilename[:-4] + '_Trajectory.png', bbox_inches="tight") if legend: leg = ax.legend((gt_call, circles), ('Truth', 'Estimate'), fontsize='xx-large', scatterpoints=3, scatteryoffsets=[.5], handlelength=2) plt.savefig(newfilename[:-4] + '_Trajectory_wLegend.png', bbox_inches="tight") plt.show()
data_text_file.write(", ") data_text_file.write(str(totalcolors[item])) data_text_file.write('\n') data_text_file.close() # make the figure! fig = plt.figure() ax = fig.add_subplot(111, xlim=(-80,80), ylim=(-80,80)) # point sizes for our circles? point size = 82, for 82 fibres #pointsizes = [17.253]*82*num pointsizes = [82]*82*num # make a collection of circles col = collections.CircleCollection(sizes=pointsizes, offsets=just_coordinates, transOffset=ax.transData) trans = transforms.Affine2D().scale(fig.dpi/72.0) # one point is 1/72 inches col.set_transform(trans) # the points to pixels transform (from example) ax.add_collection(col, autolim=True) ax.autoscale_view() # our colormap will be 'hot' in reverse, with outliers (-100) in green (but only if we're plotting line data) cust_cm = cm.hot_r cust_cm.set_bad('gray', -50) # -100 here is just the 'alpha' value for the colour, it isn't the outlier value col.set_cmap(cust_cm) col.set_norm(matplotlib.colors.Normalize()) col.set_edgecolors('black') # edge colours are an off-black hue 262626 # make a masked array from the data if data_type != 'c':
j += 1 ax = plt.gca() format_ax(ax, "Degree", "Conservatinon score") plt.plot(range(xlim + 1), [0.5] * (xlim + 1), linewidth=3, c='grey', linestyle='-') #plt.plot(range(xlim), [0.25]*xlim, linewidth=2, c='grey', linestyle='-') network_patch = [] if len(network_names) > 1: for row in patch_colors: network_patch.append( collections.CircleCollection([800] * len(row), facecolor=row, edgecolor='none')) else: #single network, no need to show color circles network_patch.append( collections.CircleCollection([800], facecolor='none', edgecolor='none')) #--------------------------------------------------- patch_colors = [x for x in zip(*patch_colors)] #--------------------------------------------------- k = 0 for row in patch_colors: patch_entries.append( collections.CircleCollection([200] * len(row), facecolor=row,