def pca(train, validate, fname=None): fig = plt.figure(1, figsize=(8, 6)) if not USE_TSNE: pca = sklearn.decomposition.PCA(n_components=2, random_state=SEED) axes = plt.gca() if not USE_TSNE: axes.set_xlim([-1.5, 1.5]) axes.set_ylim([-1.5, 1.5]) if USE_TSNE: pca = sklearn.decomposition.PCA(n_components=50, random_state=SEED) tsne = TSNE(n_components=2, verbose=2, random_state=SEED) # Fit coordinates coords = pca.fit_transform([seq['features'] for seq in (train + validate)]) if USE_TSNE: coords = tsne.fit_transform(coords) train_coords = coords[:len(train)] validate_coords = coords[len(train_coords):] for seq, coords in zip(train, train_coords): seq['coords'] = coords for seq, coords in zip(validate, validate_coords): seq['coords'] = coords for kind, dataset in zip(['train', 'validate'], [train, validate]): colors = [] all_x = [] all_y = [] for seq in dataset: category = seq['category'] x = seq['coords'][0] y = seq['coords'][1] label = seq['label'] color = COLOR_MAP(to_color(category)) marker = 'o' if kind is 'train' else '^' size = 6 if kind is 'train' else 10 alpha = 0.45 if kind is 'train' else 0.8 plt.scatter(x, y, c=[color], marker=marker, edgecolor='k', s=size, alpha=alpha, linewidths=0.0, edgecolors='none') if fname == None: plt.show() else: plt.savefig(fname=fname, dpi='figure') print("Saved image to " + fname)
def set_visible_area(point_dict, axes): min_x = 10e9 min_y = 10e9 max_x = -10e9 max_y = -10e9 for id, point in dict_utils.get_item_iterator(point_dict): min_x = min(point.x, min_x) min_y = min(point.y, min_y) max_x = max(point.x, max_x) max_y = max(point.y, max_y) axes.set_aspect('equal', adjustable='box') axes.set_xlim([min_x - 10, max_x + 10]) axes.set_ylim([min_y - 10, max_y + 10])
def set_visible_area(laneletmap, axes): min_x = 10e9 min_y = 10e9 max_x = -10e9 max_y = -10e9 for point in laneletmap.pointLayer: min_x = min(point.x, min_x) min_y = min(point.y, min_y) max_x = max(point.x, max_x) max_y = max(point.y, max_y) axes.set_aspect('equal', adjustable='box') axes.set_xlim([min_x - 10, max_x + 10]) axes.set_ylim([min_y - 10, max_y + 10])
i = 0 for X in vasShaped: corr1 = np.corrcoef(X,C1shaped)[0,1] corr2 = np.corrcoef(X,C2shaped)[0,1] corrC1.append(corr1) corrC2.append(corr2) i= i + 1 print(corrC1) print(corrC2) #Représentation graphique plt.plot(corrC2,corrC1, 'ro') axes = plt.gca() axes.set_xlim([-1.2,1.2]) axes.set_ylim([-1.2,1.2]) plt.xlabel("C1") plt.ylabel("C2") ##ajout du cercle circle1 = plt.Circle((0, 0), 1, color='r', fill= False) fig = plt.gcf() ax = fig.gca() ax.add_artist(circle1) ##ajout du nom des variables aléatoires for i, txt in enumerate(varNames): ax.annotate(txt, (corrC2[i],corrC1[i])) plt.show()
# ---------------------------CREATE FIGURES/PLOTS------------------------------ # Create upper graph fig = plt.figure(figsize=(10, 8)) ax = plt.subplot(211) # (rows, columns, plot index) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_xticks([]) ax.set_yticks([]) x_max = 10 y_max = 6 xy_min = 0 ax.set_xlim(right=x_max) ax.set_ylim(top=y_max) # Create bottom graph ax2 = plt.subplot(212) ax2.set_xlim(right=1000) ax2.set_ylim(top=70) ax2.set_xlabel('Time') ax2.set_ylabel('Total # of People Infected') # ----------------------CLASS AND FUNCTION DEFINITION-------------------------- class Person: def __init__(self, num, is_isolating): self.key = num self.x = uniform(0, x_max)
def plot_soln_frames_on_sat(args: argparse.Namespace, satellite_img: numpy.ndarray, satellite_extent: Tuple[float, float, float, float]): """Plot solution frames on a satellite image. Currently, this function is supposed to be called by `plot_depth` with multiprocessing. Argumenst --------- args : argparse.Namespace CMD argument parsed by `argparse`. satellite_img : numpy.ndarray, The RBG data for the satellite image. satellite_extent : Tuple[float, float, float, float]): The extent of the satellite image. Returns ------- Execution code. 0 for success. """ # plot fig, axes = matplotlib.pyplot.subplots() axes.imshow(satellite_img, extent=[ satellite_extent[0], satellite_extent[2], satellite_extent[1], satellite_extent[3] ]) for fno in range(args.frame_bg, args.frame_ed): print("Processing frame {} by PID {}".format(fno, os.getpid())) # read in solution data soln = pyclaw.Solution() soln.read(fno, str(args.soln_dir), file_format="binary", read_aux=args.soln_dir.joinpath( "fort.a" + "{}".format(fno).zfill(4)).is_file()) axes, imgs, _, _ = plot_soln_frame_on_ax(axes, soln, args.level, [args.cmin, args.cmax], args.dry_tol, cmap=args.cmap, border=args.border) axes.set_xlim(satellite_extent[0], satellite_extent[2]) axes.set_ylim(satellite_extent[1], satellite_extent[3]) fig.suptitle("T = {} sec".format(soln.state.t)) # title fig.savefig(args.dest_dir.joinpath( "frame{:05d}.png".format(fno))) # save # clear artists while True: try: img = imgs.pop() img.remove() del img except IndexError: break print("PID {} done processing frames {} - {}".format( os.getpid(), args.frame_bg, args.frame_ed)) return 0
def run(data): # update the data t,y = data if t>-1: xdata.append(t) ydata.append(y) #if t>xsize: # Scroll to the left. # ax.set_xlim(t-xsize, t) line.set_data(xdata, ydata) return line, def on_close_figure(event): sys.exit(0) data_gen.t = -1 fig = plt.figure() fig.canvas.mpl_connect('close_event', on_close_figure) ax = fig.add_subplot(111) line, = ax.plot([], linestyle='-.', lw=7, color = 'red') ax.set_ylim(0, 250) ax.set_xlim(0, 400) ax.grid() xdata, ydata = [], [] # Important: Although blit=True makes graphing faster, we need blit=False to prevent # spurious lines to appear when resizing the stripchart. ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=100, repeat=False) plt.show()
model = (clf1, clf2, clf3, MyCls) models = (clf.fit(X, y) for clf in model) # title for the plots titles = ('CSOVO', 'CSOVA', 'CSCS', 'Apportioned SVM') # Set-up 2x2 grid for plotting. #plt.figure() fig, sub = plt.subplots(2, 2) plt.subplots_adjust(wspace=0.4, hspace=0.4) xx, yy = make_meshgrid(X[:, 0], X[:, 1]) for clf, title, ax in zip(models, titles, sub.flatten()): plot_contours(ax, clf, xx, yy, cmap=plt.cm.coolwarm, alpha=0.8) ax.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm, s=20, edgecolors='k') ax.set_xlim(xx.min(), xx.max()) ax.set_ylim(yy.min(), yy.max()) # ax.set_xlabel('x label') # ax.set_ylabel('Sepal width') ax.set_xticks(()) ax.set_yticks(()) ax.set_title(title) plt.show()
if t > xsize: # Scroll to the left. ax.set_xlim(t - xsize, t) line.set_data(xdata, ydata) return line, def on_close_figure(event): sys.exit(0) data_gen.t = -1 fig = plt.figure() fig.canvas.mpl_connect('close_event', on_close_figure) ax = fig.add_subplot(111) line, = ax.plot(label=lines, linestyle='-.', lw=5, color='red') ax.set_ylim(0, 300) ax.set_xlim(0, xsize) ax.grid() xdata, ydata = [], [] # Important: Although blit=True makes graphing faster, we need blit=False to prevent # spurious lines to appear when resizing the stripchart. ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=100, repeat=False) plt.show()