def plot3D(show=True): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # ax = fig.gca(projection='3d') predicted = sess.run(inference(X), feed_dict={X: train_X}) x = np.squeeze(np.asarray(train_X1)) y = np.squeeze(np.asarray(train_X2)) z = np.squeeze(np.asarray(train_Y)) z1 = np.squeeze(np.asarray(predicted)) ax.plot(x, y, zs=z, c='b', label='Original') ax.plot(x, y, zs=z1, c='r', label='Fit') # ax.scatter(train_X1, train_X2, train_Y, c='y', marker='s') # ax.scatter(train_X1, train_X2, predicted, c='r', marker='v') ax.set_xlabel('X1') ax.set_ylabel('X2') ax.set_zlabel('Y') ax.legend() buf = io.BytesIO() if show: # If want to view image in Tensorboard, do not show plot => Strange # bug!!! plt.show() else: # plt.savefig("/tmp/test.png", format='png') plt.savefig(buf, format='png') buf.seek(0) return buf
def sympletic_integrator_step(dt: float, bodies: list, pairs: list, ax: Axes3D, *args, **kwargs): """A sympletic integrator to update the positions of bodies in our system of bodies. Reference --------- [1]: Sympletic Integrator on Wikipedia https://en.wikipedia.org/wiki/Symplectic_integrator """ for (([x1, y1, z1], v1, m1), ([x2, y2, z2], v2, m2)) in pairs: dx = x1 - x2 dy = y1 - y2 dz = z1 - z2 mag = dt * ((dx * dx + dy * dy + dz * dz)**(-1.5)) b1m = m1 * mag b2m = m2 * mag v1[0] -= dx * b2m v1[1] -= dy * b2m v1[2] -= dz * b2m v2[0] += dx * b1m v2[1] += dy * b1m v2[2] += dz * b1m for (r, [vx, vy, vz], m) in bodies: r[0] += dt * vx r[1] += dt * vy r[2] += dt * vz ax.clear() ax.axis("off") ax.set_xlim(-20., 20.) ax.set_ylim(-20., 20.) ax.set_zlim(-20., 20.) for ii in range(360): ax.view_init(elev=90., azim=ii) for name, body in BODIES.items(): pos, _, mass = body sc = ax.scatter(*pos, s=20 * (mass**0.3), label=name) ax.legend() return sc
def plot_loss(self, X, Y, loss, show=True): # Graphic display title = str(self.step) + ': Epochs:' + str(self.epochs) + \ " batch:" + str(self.batch_size) + \ " alpha:" + str(self.learning_rate) train_X1 = X[:, 0] fig = plt.figure() ax = fig.gca(projection='3d') ax.text2D(0.05, 0.95, title, transform=ax.transAxes) # trisurf plot # ax.plot_trisurf(np.ravel(train_X1), # np.ravel(train_X2), np.ravel(Y), color='b') ax.plot_trisurf(np.ravel(train_X1), np.ravel(Y), np.ravel(loss)) ax.set_xlabel('Weight') ax.set_ylabel('bias') ax.set_zlabel('Loss') ax.legend() # save image to buffer buf = io.BytesIO() if show: # If want to view image in Tensorboard, do not show plot => Strange # bug!!! image_path = self.logs_path + "/images" if not os.path.exists(image_path): os.mkdir(image_path) filename = image_path + "/" + \ "loss-" + \ time.strftime("%Y%m%d-%H%M%S", time.localtime()) + ".png" plt.savefig(filename, format='png') plt.show() else: plt.savefig(buf, format='png') buf.seek(0) plt.close() # plt.clf() return buf
def plot(self, show=True): # Graphic display predicted = self.sess.run(self.inference(reuse=True), feed_dict={self.X: self.input_X}) title = 'Epochs:' + str(self.epochs) + \ " batch:" + str(self.batch_size) + \ " layers:" + str(self.n_layers) + \ " neurons:" + str(self.n_neurals) + \ " alpha:" + str(self.learning_rate) if self.n_features == 1: # plot 2D image plt.title(title) # plt.plot(self.train_X, self.train_Y, c='b', label='Original data') # plt.plot(self.train_X, predicted, c='r', label='Fitted') plt.scatter(self.input_X, self.label_Y, c='b', label='Original data') plt.scatter(self.input_X, predicted, c='r', label='Fitted') plt.legend() else: # plot 3D for X1, X2 if (self.n_features == 2): train_X1, train_X2 = np.hsplit(self.input_X, self.n_features) else: train_X1, train_X2, _ = np.hsplit(self.input_X, self.n_features) fig = plt.figure() # ax = fig.add_subplot(111, projection='3d') ax = fig.gca(projection='3d') ax.text2D(0.05, 0.95, title, transform=ax.transAxes) x = np.squeeze(np.asarray(train_X1)) y = np.squeeze(np.asarray(train_X2)) z = np.squeeze(np.asarray(self.label_Y)) z1 = np.squeeze(np.asarray(predicted)) # ax.plot(x, y, zs=z, c='b', label='Original data') # ax.plot(x, y, zs=z1, c='r', label='Fitted') ax.scatter(train_X1, train_X2, self.label_Y, c='b', marker='s', label='Original data') ax.scatter(train_X1, train_X2, predicted, c='r', marker='v', label='Fitted') ax.set_xlabel('X1') ax.set_ylabel('X2') ax.set_zlabel('Y') ax.legend() # save image to buffer buf = io.BytesIO() if show: # If want to view image in Tensorboard, do not show plot => Strange # bug!!! image_path = self.logs_path + "/images" if not os.path.exists(image_path): os.mkdir(image_path) filename = image_path + "/" + \ time.strftime("%Y%m%d-%H%M%S", time.localtime()) + ".png" plt.savefig(filename, format='png') plt.show() else: plt.savefig(buf, format='png') buf.seek(0) plt.close('all') return buf
plt.title('I hate datasets line graph') plt.xlabel('County Name') plt.ylabel('Average Upload number') plt.tight_layout(pad=0.5) plt.show() ################### 3d graph implementation #creating graph based on min, max, avg fig = plt.figure() ax = fig.add_subplot(111, projection='3d') #ax.scatter(y,z,w,color='blue',marker='o') for (k, v) in enumerate(y): ax.scatter(y[k], z[k], w[k], marker='o') #ax.legend([x[k]]) ax.legend(x) ax.set_title('I hate datasets in 3d') ax.set_xlabel('min') ax.set_ylabel('Max') ax.set_zlabel('Avg') plt.show() ############## hw 3 portion #brings in data and sends it into gudhi distance_matrix = gudhi.read_lower_triangular_matrix_from_csv_file( csv_file='Maryland_Broadband_Speed_Test__County_Upload.csv') rips_complex = gudhi.RipsComplex(distance_matrix=distance_matrix, max_edge_length=12.0) #setting parameters simplex_tree = rips_complex.create_simplex_tree(max_dimension=1) result_str = 'Rips complex is of dimension ' + repr(simplex_tree.dimension()) + ' - ' + \ repr(simplex_tree.num_simplices()) + ' simplices - ' + \
#%pylab inline import math import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D as ax x = np.arange(0, 10, 0.1) y = np.sin(x) fig, ax = plt.subplots(facecolor='w', edgecolor='k') ax.plot(x, y, marker="o", color="r", linestyle='None') ax.grid(True) ax.set_xlabel('X') ax.set_ylabel('Y') ax.grid(True) ax.legend(["y = x**2"]) plt.title('Puntos') plt.show() fig.savefig("grafica.png")
def plot(self, X, Y, show=True): # Graphic display predicted = self.sess.run(self.predict_model(X)) title = str(self.step) + ': Epochs:' + str(self.epochs) + \ " batch:" + str(self.batch_size) + \ " alpha:" + str(self.learning_rate) if self.n_features == 1: # plot 2D image plt.title(title) # plt.plot(self.train_X, self.train_Y, c='b', label='Original data') # plt.plot(self.train_X, predicted, c='r', label='Fitted') plt.scatter(X, Y, c='b', label='Original data') plt.scatter(X, predicted, c='r', label='Fitted') plt.legend() else: # plot 3D for X1, X2 if (self.n_features == 2): train_X1, train_X2 = np.hsplit(X, self.n_features) else: train_X1, train_X2, _ = np.hsplit(X, self.n_features) fig = plt.figure() ax = fig.gca(projection='3d') ax.text2D(0.05, 0.95, title, transform=ax.transAxes) # line plot # x = np.squeeze(np.asarray(train_X1)) # y = np.squeeze(np.asarray(train_X2)) # z = np.squeeze(np.asarray(Y)) # z1 = np.squeeze(np.asarray(predicted)) # ax.plot(x, y, zs=z, c='b', label='Original data') # ax.plot(x, y, zs=z1, c='r', label='Fitted') # statter plot ax.scatter(train_X1, train_X2, Y, c='b', marker='s', label='Original data') # ax.scatter(train_X1, train_X2, predicted, # c='r', marker='v', label='Fitted') # trisurf plot # ax.plot_trisurf(np.ravel(train_X1), # np.ravel(train_X2), np.ravel(Y), color='b') ax.plot_trisurf(np.ravel(train_X1), np.ravel(train_X2), np.ravel(predicted), color='r') ax.set_xlabel('X1') ax.set_ylabel('X2') ax.set_zlabel('Y') ax.legend() # save image to buffer buf = io.BytesIO() if show: # If want to view image in Tensorboard, do not show plot => Strange # bug!!! image_path = self.logs_path + "/images" if not os.path.exists(image_path): os.mkdir(image_path) filename = image_path + "/" + \ time.strftime("%Y%m%d-%H%M%S", time.localtime()) + ".png" plt.savefig(filename, format='png') plt.show() else: plt.savefig(buf, format='png') buf.seek(0) plt.close() # plt.clf() return buf