def plot_boundary(model, x, y, **kwargs): assert (x.shape[-1] == 2) cmap_light = ListedColormap(['#FFAAAA', '#AAFFAA', '#AAAAFF']) cmap_bold = ListedColormap(['#FF0000', '#00FF00', '#0000FF']) if 'h' in kwargs: h = kwargs['h'] else: h = 0.1 x_min, x_max = x[:, 0].min() - 1, x[:, 0].max() + 1 y_min, y_max = x[:, 1].min() - 1, x[:, 1].max() + 1 x_grid, y_grid = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h)) Z = model.predict(np.c_[x_grid.ravel(), y_grid.ravel()]) # Put the result into a color plot Z = Z.reshape(x_grid.shape) plt.figure() plt.pcolormesh(x_grid, y_grid, Z, cmap=cmap_light) # Plot also the training points plt.scatter(x[:, 0], x[:, 1], c=y, cmap=cmap_bold, edgecolor='k', s=20) plt.xlim(x_grid.min(), x_grid.max()) plt.ylim(y_grid.min(), y_grid.max()) if 'title' in kwargs: plt.suptitle(kwargs['title']) if 'accuracy' in kwargs: plt.title("Accuracy: %.1f%%" % (kwargs['accuracy'] * 100), fontsize=10) plt.show()
def forward(self, x): # polar plot dic = creatRealDictionary(self.T, self.rr, self.theta, self.gid) sparsecode = fista(dic, x, self.lam, 100, self.gid) if random.randint(1, 20) == 1: plt.figure() plt.pcolormesh(sparsecode[0, :, :].data.cpu().detach().numpy(), cmap='RdBu') plt.colorbar() plt.savefig('C_evolution_subsIni.png') #, dpi=200 # plt.show() plt.close() rr = self.rr.data.cpu().detach().numpy() theta = self.theta.data.cpu().detach().numpy() ax = plt.subplot(1, 1, 1, projection='polar') ax.scatter(0, 1, c='black') # unactive poles ax.scatter(theta, rr) ax.scatter(-theta, rr) ax.scatter(np.pi - theta, rr) ax.scatter(theta - np.pi, rr) # ax.set_rmax(1.2) ax.set_title("Dictionary", va='bottom') plt.savefig('usedPolesDCT.png') # plt.show() plt.close() return Variable(sparsecode)
def estimate_coord_plot(feten): lon_res = 13 lat_res = 9 nz = 26 lat_step = 0.5 lon_step = 0.5 lat_start = 44 lat_end = lat_start + lat_step * (lat_res - 1) # calculas lat final lon_start = -123 lon_end = lon_start + lon_step * ( lon_res - 1) # calculas lon final - con esto puedes construir mesh lat = np.linspace(start=lat_start, stop=lat_end, endpoint=lat_end, num=lat_res) lon = np.linspace(start=lon_start, stop=lon_end, endpoint=lon_end, num=lon_res) # lon, lat = np.meshgrid(lon, lat) Z = feten.reshape(lat_res, lon_res) ptos = np.hstack((lat.reshape((lat.size, 1)), lon.reshape((lon.size, 1)))) fig = plt.figure(figsize=(12, 10)) im = plt.pcolormesh(lat, lon, Z) # Asignas valores a su posición en el mapa return plt.colorbar(mappable=im)
def lets_paint_the_world(file): filee = open(filename) filee lon = [] lat = [] depth = [] counter = 0 for line in filee.readlines(): #set a counter because computer couldn't run the whole file if counter < 1000: each_line = line.split() lon.append(float(each_line[0][:])) lat.append(float(each_line[1][:])) depth.append(float(each_line[2][:])) counter += 1 m = Basemap(projection = 'tmerc', llcrnrlon= -180, urcrnrlon = 180, llcrnrlat= -90, urcrnrlat = 90, lat_0= 0, lon_0= 0) #creates the graticule based on the coor x, y = m(*np.meshgrid(lon,lat))#<----------BREAKING POINT #plot commands fig = plt.figure(figsize=(10,7)) ax = fig.add_subplot(111) #draws m.fillcontinents(color='coral', lake_color='aqua') m.drawcoastlines(linewidth = .25) m.drawcountries(linewidth = .25) m.drawmeridians(np.arange(0, 360, 15)) m.drawparallels(np.arange(-90, 90, 15)) plt.pcolormesh(x,y,depth, [-1000,0,1000], cmap=plt.cm.RdBu_r, vmin=-100, vmax = 100) plt.show()
cb = m.colorbar(pcm) cb.set_label('Soil FOO (mm)') plt.show() pylab.figure(num=None, figsize=(20,10), dpi=100) plt.title("Importance of Different Colormaps") pylab.subplot(2,2,1) plotpanel(x, y, soil) pcm = plt.pcolormesh(x, y, soil, cmap=plt.cm.nipy_spectral) cb = m.colorbar(pcm) cb.set_label('Soil FOO (mm)') pylab.title("nipy_spectral (best)") pylab.subplot(2,2,2) plotpanel(x, y, soil) pylab.title("Accent (okay)") pcm = plt.pcolormesh(x, y, soil, cmap=plt.cm.Accent) cb = m.colorbar(pcm) cb.set_label('Soil FOO (mm)') pylab.subplot(2,2,4) plotpanel(x, y, soil)