Python pylab.scatter() Examples
The following are 30
code examples of pylab.scatter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pylab
, or try the search function
.
Example #1
Source File: homework1.py From principles-of-computing with MIT License | 7 votes |
def plot_question7(): ''' graph of total resources generated as a function of time, for upgrade_cost_increment == 1 ''' data = resources_vs_time(1.0, 50) time = [item[0] for item in data] resource = [item[1] for item in data] a, b, c = pylab.polyfit(time, resource, 2) print 'polyfit with argument \'2\' fits the data, thus the degree of the polynomial is 2 (quadratic)' # plot in pylab on logarithmic scale (total resources over time for upgrade growth 0.0) #pylab.loglog(time, resource, 'o') # plot fitting function yp = pylab.polyval([a, b, c], time) pylab.plot(time, yp) pylab.scatter(time, resource) pylab.title('Silly Homework, Question 7') pylab.legend(('Resources for increment 1', 'Fitting function' + ', slope: ' + str(a))) pylab.xlabel('Current Time') pylab.ylabel('Total Resources Generated') pylab.grid() pylab.show()
Example #2
Source File: proj3d.py From opticspy with MIT License | 7 votes |
def test_lines_dists(): import pylab ax = pylab.gca() xs, ys = (0,30), (20,150) pylab.plot(xs, ys) points = list(zip(xs, ys)) p0, p1 = points xs, ys = (0,0,20,30), (100,150,30,200) pylab.scatter(xs, ys) dist = line2d_seg_dist(p0, p1, (xs[0], ys[0])) dist = line2d_seg_dist(p0, p1, np.array((xs, ys))) for x, y, d in zip(xs, ys, dist): c = Circle((x, y), d, fill=0) ax.add_patch(c) pylab.xlim(-200, 200) pylab.ylim(-200, 200) pylab.show()
Example #3
Source File: proj3d.py From opticspy with MIT License | 7 votes |
def test_proj(): import pylab M = test_proj_make_M() ts = ['%d' % i for i in [0,1,2,3,0,4,5,6,7,4]] xs, ys, zs = [0,1,1,0,0, 0,1,1,0,0], [0,0,1,1,0, 0,0,1,1,0], \ [0,0,0,0,0, 1,1,1,1,1] xs, ys, zs = [np.array(v)*300 for v in (xs, ys, zs)] # test_proj_draw_axes(M, s=400) txs, tys, tzs = proj_transform(xs, ys, zs, M) ixs, iys, izs = inv_transform(txs, tys, tzs, M) pylab.scatter(txs, tys, c=tzs) pylab.plot(txs, tys, c='r') for x, y, t in zip(txs, tys, ts): pylab.text(x, y, t) pylab.xlim(-0.2, 0.2) pylab.ylim(-0.2, 0.2) pylab.show()
Example #4
Source File: helpers.py From sklearn_pydata2015 with BSD 3-Clause "New" or "Revised" License | 6 votes |
def plot_iris_knn(): iris = datasets.load_iris() X = iris.data[:, :2] # we only take the first two features. We could # avoid this ugly slicing by using a two-dim dataset y = iris.target knn = neighbors.KNeighborsClassifier(n_neighbors=3) knn.fit(X, y) x_min, x_max = X[:, 0].min() - .1, X[:, 0].max() + .1 y_min, y_max = X[:, 1].min() - .1, X[:, 1].max() + .1 xx, yy = np.meshgrid(np.linspace(x_min, x_max, 100), np.linspace(y_min, y_max, 100)) Z = knn.predict(np.c_[xx.ravel(), yy.ravel()]) # Put the result into a color plot Z = Z.reshape(xx.shape) pl.figure() pl.pcolormesh(xx, yy, Z, cmap=cmap_light) # Plot also the training points pl.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold) pl.xlabel('sepal length (cm)') pl.ylabel('sepal width (cm)') pl.axis('tight')
Example #5
Source File: helpers.py From MachineLearning with BSD 3-Clause "New" or "Revised" License | 6 votes |
def plot_iris_knn(): iris = datasets.load_iris() X = iris.data[:, :2] # we only take the first two features. We could # avoid this ugly slicing by using a two-dim dataset y = iris.target knn = neighbors.KNeighborsClassifier(n_neighbors=3) knn.fit(X, y) x_min, x_max = X[:, 0].min() - .1, X[:, 0].max() + .1 y_min, y_max = X[:, 1].min() - .1, X[:, 1].max() + .1 xx, yy = np.meshgrid(np.linspace(x_min, x_max, 100), np.linspace(y_min, y_max, 100)) Z = knn.predict(np.c_[xx.ravel(), yy.ravel()]) # Put the result into a color plot Z = Z.reshape(xx.shape) pl.figure() pl.pcolormesh(xx, yy, Z, cmap=cmap_light) # Plot also the training points pl.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold) pl.xlabel('sepal length (cm)') pl.ylabel('sepal width (cm)') pl.axis('tight')
Example #6
Source File: helpers.py From ESAC-stats-2014 with BSD 2-Clause "Simplified" License | 6 votes |
def plot_iris_knn(): iris = datasets.load_iris() X = iris.data[:, :2] # we only take the first two features. We could # avoid this ugly slicing by using a two-dim dataset y = iris.target knn = neighbors.KNeighborsClassifier(n_neighbors=3) knn.fit(X, y) x_min, x_max = X[:, 0].min() - .1, X[:, 0].max() + .1 y_min, y_max = X[:, 1].min() - .1, X[:, 1].max() + .1 xx, yy = np.meshgrid(np.linspace(x_min, x_max, 100), np.linspace(y_min, y_max, 100)) Z = knn.predict(np.c_[xx.ravel(), yy.ravel()]) # Put the result into a color plot Z = Z.reshape(xx.shape) pl.figure() pl.pcolormesh(xx, yy, Z, cmap=cmap_light) # Plot also the training points pl.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold) pl.xlabel('sepal length (cm)') pl.ylabel('sepal width (cm)') pl.axis('tight')
Example #7
Source File: main.py From scTDA with GNU General Public License v3.0 | 6 votes |
def plot_CDR_correlation(self, doplot=True): """ Displays correlation between sampling time points and CDR. It returns the two parameters of the linear fit, Pearson's r, p-value and standard error. If optional argument 'doplot' is False, the plot is not displayed. """ pel2, tol = self.get_gene(self.rootlane, ignore_log=True) pel = numpy.array([pel2[m] for m in self.pl])*tol dr2 = self.get_gene('_CDR')[0] dr = numpy.array([dr2[m] for m in self.pl]) po = scipy.stats.linregress(pel, dr) if doplot: pylab.scatter(pel, dr, s=9.0, alpha=0.7, c='r') pylab.xlim(min(pel), max(pel)) pylab.ylim(0, max(dr)*1.1) pylab.xlabel(self.rootlane) pylab.ylabel('CDR') xk = pylab.linspace(min(pel), max(pel), 50) pylab.plot(xk, po[1]+po[0]*xk, 'k--', linewidth=2.0) pylab.show() return po
Example #8
Source File: main.py From scTDA with GNU General Public License v3.0 | 6 votes |
def __init__(self, table, lens='mds', metric='correlation', precomputed=False, **kwargs): """ Initializes the class by providing the mapper input table generated by Preprocess.save(). The parameter 'metric' specifies the metric distance to be used ('correlation', 'euclidean' or 'neighbor'). The parameter 'lens' specifies the dimensional reduction algorithm to be used ('mds' or 'pca'). The rest of the arguments are passed directly to sklearn.manifold.MDS or sklearn.decomposition.PCA. It plots the low-dimensional projection of the data. """ self.df = pandas.read_table(table + '.mapper.tsv') if lens == 'neighbor': self.lens_data_mds = sakmapper.apply_lens(self.df, lens=lens, **kwargs) elif lens == 'mds': if precomputed: self.lens_data_mds = sakmapper.apply_lens(self.df, lens=lens, metric=metric, dissimilarity='precomputed', **kwargs) else: self.lens_data_mds = sakmapper.apply_lens(self.df, lens=lens, metric=metric, **kwargs) else: self.lens_data_mds = sakmapper.apply_lens(self.df, lens=lens, **kwargs) pylab.figure() pylab.scatter(numpy.array(self.lens_data_mds)[:, 0], numpy.array(self.lens_data_mds)[:, 1], s=10, alpha=0.7) pylab.show()
Example #9
Source File: fix_shot_times.py From nba-movement-data with MIT License | 6 votes |
def plot(t, plots, shot_ind): n = len(plots) for i in range(0,n): label, data = plots[i] plt = py.subplot(n, 1, i+1) plt.tick_params(labelsize=8) py.grid() py.xlim([t[0], t[-1]]) py.ylabel(label) py.plot(t, data, 'k-') py.scatter(t[shot_ind], data[shot_ind], marker='*', c='g') py.xlabel("Time") py.show() py.close()
Example #10
Source File: followup.py From pycbc with GNU General Public License v3.0 | 6 votes |
def coinc_timeseries_plot(coinc_file, start, end): fig = pylab.figure() f = h5py.File(coinc_file, 'r') stat1 = f['foreground/stat1'] stat2 = f['foreground/stat2'] time1 = f['foreground/time1'] time2 = f['foreground/time2'] ifo1 = f.attrs['detector_1'] ifo2 = f.attrs['detector_2'] pylab.scatter(time1, stat1, label=ifo1, color=ifo_color[ifo1]) pylab.scatter(time2, stat2, label=ifo2, color=ifo_color[ifo2]) fmt = '.12g' mpld3.plugins.connect(fig, mpld3.plugins.MousePosition(fmt=fmt)) pylab.legend() pylab.xlabel('Time (s)') pylab.ylabel('NewSNR') pylab.grid() return mpld3.fig_to_html(fig)
Example #11
Source File: followup.py From pycbc with GNU General Public License v3.0 | 6 votes |
def trigger_timeseries_plot(file_list, ifos, start, end): fig = pylab.figure() for ifo in ifos: trigs = columns_from_file_list(file_list, ['snr', 'end_time'], ifo, start, end) print(trigs) pylab.scatter(trigs['end_time'], trigs['snr'], label=ifo, color=ifo_color[ifo]) fmt = '.12g' mpld3.plugins.connect(fig, mpld3.plugins.MousePosition(fmt=fmt)) pylab.legend() pylab.xlabel('Time (s)') pylab.ylabel('SNR') pylab.grid() return mpld3.fig_to_html(fig)
Example #12
Source File: homework1.py From principles-of-computing with MIT License | 6 votes |
def polyfitting(): ''' helper function to play around with polyfit from: http://www.wired.com/2011/01/linear-regression-with-pylab/ ''' x = [0.2, 1.3, 2.1, 2.9, 3.3] y = [3.3, 3.9, 4.8, 5.5, 6.9] slope, intercept = pylab.polyfit(x, y, 1) print 'slope:', slope, 'intercept:', intercept yp = pylab.polyval([slope, intercept], x) pylab.plot(x, yp) pylab.scatter(x, y) pylab.show() #polyfitting()
Example #13
Source File: proj3d.py From matplotlib-4-abaqus with MIT License | 6 votes |
def test_proj(): import pylab M = test_proj_make_M() ts = ['%d' % i for i in [0,1,2,3,0,4,5,6,7,4]] xs, ys, zs = [0,1,1,0,0, 0,1,1,0,0], [0,0,1,1,0, 0,0,1,1,0], \ [0,0,0,0,0, 1,1,1,1,1] xs, ys, zs = [np.array(v)*300 for v in (xs, ys, zs)] # test_proj_draw_axes(M, s=400) txs, tys, tzs = proj_transform(xs, ys, zs, M) ixs, iys, izs = inv_transform(txs, tys, tzs, M) pylab.scatter(txs, tys, c=tzs) pylab.plot(txs, tys, c='r') for x, y, t in zip(txs, tys, ts): pylab.text(x, y, t) pylab.xlim(-0.2, 0.2) pylab.ylim(-0.2, 0.2) pylab.show()
Example #14
Source File: proj3d.py From matplotlib-4-abaqus with MIT License | 6 votes |
def test_lines_dists(): import pylab ax = pylab.gca() xs, ys = (0,30), (20,150) pylab.plot(xs, ys) points = zip(xs, ys) p0, p1 = points xs, ys = (0,0,20,30), (100,150,30,200) pylab.scatter(xs, ys) dist = line2d_seg_dist(p0, p1, (xs[0], ys[0])) dist = line2d_seg_dist(p0, p1, np.array((xs, ys))) for x, y, d in zip(xs, ys, dist): c = Circle((x, y), d, fill=0) ax.add_patch(c) pylab.xlim(-200, 200) pylab.ylim(-200, 200) pylab.show()
Example #15
Source File: proj3d.py From Computable with MIT License | 6 votes |
def test_proj(): import pylab M = test_proj_make_M() ts = ['%d' % i for i in [0,1,2,3,0,4,5,6,7,4]] xs, ys, zs = [0,1,1,0,0, 0,1,1,0,0], [0,0,1,1,0, 0,0,1,1,0], \ [0,0,0,0,0, 1,1,1,1,1] xs, ys, zs = [np.array(v)*300 for v in (xs, ys, zs)] # test_proj_draw_axes(M, s=400) txs, tys, tzs = proj_transform(xs, ys, zs, M) ixs, iys, izs = inv_transform(txs, tys, tzs, M) pylab.scatter(txs, tys, c=tzs) pylab.plot(txs, tys, c='r') for x, y, t in zip(txs, tys, ts): pylab.text(x, y, t) pylab.xlim(-0.2, 0.2) pylab.ylim(-0.2, 0.2) pylab.show()
Example #16
Source File: proj3d.py From Computable with MIT License | 6 votes |
def test_lines_dists(): import pylab ax = pylab.gca() xs, ys = (0,30), (20,150) pylab.plot(xs, ys) points = zip(xs, ys) p0, p1 = points xs, ys = (0,0,20,30), (100,150,30,200) pylab.scatter(xs, ys) dist = line2d_seg_dist(p0, p1, (xs[0], ys[0])) dist = line2d_seg_dist(p0, p1, np.array((xs, ys))) for x, y, d in zip(xs, ys, dist): c = Circle((x, y), d, fill=0) ax.add_patch(c) pylab.xlim(-200, 200) pylab.ylim(-200, 200) pylab.show()
Example #17
Source File: plotting.py From webvectors with GNU General Public License v3.0 | 5 votes |
def embed(words, matrix, classes, usermodel, fname): perplexity = int(len(words) ** 0.5) # We set perplexity to a square root of the words number embedding = TSNE(n_components=2, perplexity=perplexity, metric='cosine', n_iter=500, init='pca') y = embedding.fit_transform(matrix) print('2-d embedding finished', file=sys.stderr) class_set = [c for c in set(classes)] colors = plot.cm.rainbow(np.linspace(0, 1, len(class_set))) class2color = [colors[class_set.index(w)] for w in classes] xpositions = y[:, 0] ypositions = y[:, 1] seen = set() plot.clf() for color, word, class_label, x, y in zip(class2color, words, classes, xpositions, ypositions): plot.scatter(x, y, 20, marker='.', color=color, label=class_label if class_label not in seen else "") seen.add(class_label) lemma = word.split('_')[0].replace('::', ' ') mid = len(lemma) / 2 mid *= 4 # TODO Should really think about how to adapt this variable to the real plot size plot.annotate(lemma, xy=(x - mid, y), size='x-large', weight='bold', fontproperties=font, color=color) plot.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plot.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) plot.legend(loc='best') plot.savefig(root + 'data/images/tsneplots/' + usermodel + '_' + fname + '.png', dpi=150, bbox_inches='tight') plot.close() plot.clf()
Example #18
Source File: test_aliasedcorrelate.py From rapidtide with Apache License 2.0 | 5 votes |
def test_aliasedcorrelate(display=False): Fs_hi = 10.0 Fs_lo = 1.0 siginfo = [[1.0, 1.36129345], [0.33, 2.0]] modamp = 0.01 inlenhi = 1000 inlenlo = 100 offset = 0.5 width = 2.5 rangepts = 101 timerange = np.linspace(0.0, width, num=101) - width / 2.0 hiaxis = np.linspace(0.0, 2.0 * np.pi * inlenhi / Fs_hi, num=inlenhi, endpoint=False) loaxis = np.linspace(0.0, 2.0 * np.pi * inlenlo / Fs_lo, num=inlenlo, endpoint=False) sighi = hiaxis * 0.0 siglo = loaxis * 0.0 for theinfo in siginfo: sighi += theinfo[0] * np.sin(theinfo[1] * hiaxis) siglo += theinfo[0] * np.sin(theinfo[1] * loaxis) aliasedcorrelate_result = aliasedcorrelate(sighi, Fs_hi, siglo, Fs_lo, timerange, padvalue=width) thecorrelator = aliasedcorrelator(sighi, Fs_hi, Fs_lo, timerange, padvalue=width) aliasedcorrelate_result2 = thecorrelator.apply(siglo, 0.0) if display: plt.figure() #plt.ylim([-1.0, 3.0]) plt.plot(hiaxis, sighi, 'k') plt.scatter(loaxis, siglo, c='r') plt.legend(['sighi', 'siglo']) plt.figure() plt.plot(timerange, aliasedcorrelate_result, 'k') plt.plot(timerange, aliasedcorrelate_result2, 'r') print('maximum occurs at offset', timerange[np.argmax(aliasedcorrelate_result)]) plt.show() #assert (fastcorrelate_result == stdcorrelate_result).all aethresh = 10 #np.testing.assert_almost_equal(fastcorrelate_result, stdcorrelate_result, aethresh)
Example #19
Source File: gambler.py From rl with MIT License | 5 votes |
def print_values(self, values): pylab.scatter(range(len(values)), values) pylab.xlabel('credit') pylab.ylabel('expected return') pylab.show()
Example #20
Source File: gambler.py From rl with MIT License | 5 votes |
def print_policy(self, policy): pylab.scatter(range(len(policy)), policy) pylab.xlabel('credit') pylab.ylabel('bet') pylab.show()
Example #21
Source File: helpers.py From ESAC-stats-2014 with BSD 2-Clause "Simplified" License | 5 votes |
def plot_polynomial_regression(): rng = np.random.RandomState(0) x = 2*rng.rand(100) - 1 f = lambda t: 1.2 * t**2 + .1 * t**3 - .4 * t **5 - .5 * t ** 9 y = f(x) + .4 * rng.normal(size=100) x_test = np.linspace(-1, 1, 100) pl.figure() pl.scatter(x, y, s=4) X = np.array([x**i for i in range(5)]).T X_test = np.array([x_test**i for i in range(5)]).T regr = linear_model.LinearRegression() regr.fit(X, y) pl.plot(x_test, regr.predict(X_test), label='4th order') X = np.array([x**i for i in range(10)]).T X_test = np.array([x_test**i for i in range(10)]).T regr = linear_model.LinearRegression() regr.fit(X, y) pl.plot(x_test, regr.predict(X_test), label='9th order') pl.legend(loc='best') pl.axis('tight') pl.title('Fitting a 4th and a 9th order polynomial') pl.figure() pl.scatter(x, y, s=4) pl.plot(x_test, f(x_test), label="truth") pl.axis('tight') pl.title('Ground truth (9th order polynomial)')
Example #22
Source File: helpers.py From MachineLearning with BSD 3-Clause "New" or "Revised" License | 5 votes |
def plot_polynomial_regression(): rng = np.random.RandomState(0) x = 2*rng.rand(100) - 1 f = lambda t: 1.2 * t**2 + .1 * t**3 - .4 * t **5 - .5 * t ** 9 y = f(x) + .4 * rng.normal(size=100) x_test = np.linspace(-1, 1, 100) pl.figure() pl.scatter(x, y, s=4) X = np.array([x**i for i in range(5)]).T X_test = np.array([x_test**i for i in range(5)]).T regr = linear_model.LinearRegression() regr.fit(X, y) pl.plot(x_test, regr.predict(X_test), label='4th order') X = np.array([x**i for i in range(10)]).T X_test = np.array([x_test**i for i in range(10)]).T regr = linear_model.LinearRegression() regr.fit(X, y) pl.plot(x_test, regr.predict(X_test), label='9th order') pl.legend(loc='best') pl.axis('tight') pl.title('Fitting a 4th and a 9th order polynomial') pl.figure() pl.scatter(x, y, s=4) pl.plot(x_test, f(x_test), label="truth") pl.axis('tight') pl.title('Ground truth (9th order polynomial)')
Example #23
Source File: visu_classification.py From JDOT with MIT License | 5 votes |
def plot_data_classif(X,y,Z=None): if not Z is None: pl.pcolormesh(xx, yy,np.argmax(Z,2),edgecolors='face',alpha=.1, vmin=0, vmax=2) pl.scatter(X[:,i1],X[:,i2],c=y,edgecolors='black')#,cmap='Pastel2')
Example #24
Source File: review_analysis.py From yelp with GNU Lesser General Public License v2.1 | 5 votes |
def simple_lineal_regression(file_path): records = ReviewETL.load_file(file_path) data = [[record['review_count']] for record in records] ratings = [record['stars'] for record in records] num_testing_records = int(len(ratings) * 0.8) training_data = data[:num_testing_records] testing_data = data[num_testing_records:] training_ratings = ratings[:num_testing_records] testing_ratings = ratings[num_testing_records:] # Create linear regression object regr = linear_model.LinearRegression() # Train the model using the training sets regr.fit(training_data, training_ratings) # The coefficients print('Coefficients: \n', regr.coef_) print('Intercept: \n', regr.intercept_) # The root mean square error print("RMSE: %.2f" % (np.mean( (regr.predict(testing_data) - testing_ratings) ** 2)) ** 0.5) print( 'Variance score: %.2f' % regr.score(testing_data, testing_ratings)) # Plot outputs import pylab as pl pl.scatter(testing_data, testing_ratings, color='black') pl.plot(testing_data, regr.predict(testing_data), color='blue', linewidth=3) pl.xticks(()) pl.yticks(()) pl.show()
Example #25
Source File: main.py From scTDA with GNU General Public License v3.0 | 5 votes |
def plot_rootlane_correlation(self): """ Displays correlation between sampling time points and graph distance to root node. It returns the two parameters of the linear fit, Pearson's r, p-value and standard error. """ pylab.scatter(self.pel, self.dr, s=9.0, alpha=0.7, c='r') pylab.xlim(min(self.pel), max(self.pel)) pylab.ylim(0, max(self.dr)+1) pylab.xlabel(self.rootlane) pylab.ylabel('Distance to root node') xk = pylab.linspace(min(self.pel), max(self.pel), 50) pylab.plot(xk, self.po[1]+self.po[0]*xk, 'k--', linewidth=2.0) pylab.show() return self.po
Example #26
Source File: xmeans.py From msaf with MIT License | 5 votes |
def test_kmeans(K=5): """Test k-means with the synthetic data.""" X = XMeans.generate_2d_data(K=4) wX = vq.whiten(X) dic, dist = vq.kmeans(wX, K, iter=100) plt.scatter(wX[:, 0], wX[:, 1]) plt.scatter(dic[:, 0], dic[:, 1], color="m") plt.show()
Example #27
Source File: helpers.py From sklearn_pydata2015 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def plot_polynomial_regression(): rng = np.random.RandomState(0) x = 2*rng.rand(100) - 1 f = lambda t: 1.2 * t**2 + .1 * t**3 - .4 * t **5 - .5 * t ** 9 y = f(x) + .4 * rng.normal(size=100) x_test = np.linspace(-1, 1, 100) pl.figure() pl.scatter(x, y, s=4) X = np.array([x**i for i in range(5)]).T X_test = np.array([x_test**i for i in range(5)]).T regr = linear_model.LinearRegression() regr.fit(X, y) pl.plot(x_test, regr.predict(X_test), label='4th order') X = np.array([x**i for i in range(10)]).T X_test = np.array([x_test**i for i in range(10)]).T regr = linear_model.LinearRegression() regr.fit(X, y) pl.plot(x_test, regr.predict(X_test), label='9th order') pl.legend(loc='best') pl.axis('tight') pl.title('Fitting a 4th and a 9th order polynomial') pl.figure() pl.scatter(x, y, s=4) pl.plot(x_test, f(x_test), label="truth") pl.axis('tight') pl.title('Ground truth (9th order polynomial)')
Example #28
Source File: plot.py From thesne with MIT License | 5 votes |
def plot(Y, labels): pylab.scatter(Y[:, 0], Y[:, 1], s=30, c=labels, cmap=colors, linewidth=0) pylab.show()
Example #29
Source File: megafacade.py From facade-segmentation with MIT License | 5 votes |
def plot_facade_cuts(self): facade_sig = self.facade_edge_scores.sum(0) facade_cuts = find_facade_cuts(facade_sig, dilation_amount=self.facade_merge_amount) mu = np.mean(facade_sig) sigma = np.std(facade_sig) w = self.rectified.shape[1] pad=10 gs1 = pl.GridSpec(5, 5) gs1.update(wspace=0.5, hspace=0.0) # set the spacing between axes. pl.subplot(gs1[:3, :]) pl.imshow(self.rectified) pl.vlines(facade_cuts, *pl.ylim(), lw=2, color='black') pl.axis('off') pl.xlim(-pad, w+pad) pl.subplot(gs1[3:, :], sharex=pl.gca()) pl.fill_between(np.arange(w), 0, facade_sig, lw=0, color='red') pl.fill_between(np.arange(w), 0, np.clip(facade_sig, 0, mu+sigma), color='blue') pl.plot(np.arange(w), facade_sig, color='blue') pl.vlines(facade_cuts, facade_sig[facade_cuts], pl.xlim()[1], lw=2, color='black') pl.scatter(facade_cuts, facade_sig[facade_cuts]) pl.axis('off') pl.hlines(mu, 0, w, linestyle='dashed', color='black') pl.text(0, mu, '$\mu$ ', ha='right') pl.hlines(mu + sigma, 0, w, linestyle='dashed', color='gray',) pl.text(0, mu + sigma, '$\mu+\sigma$ ', ha='right') pl.xlim(-pad, w+pad)
Example #30
Source File: vision.py From DFace with Apache License 2.0 | 4 votes |
def vis_face(im_array, dets, landmarks=None): """Visualize detection results before and after calibration Parameters: ---------- im_array: numpy.ndarray, shape(1, c, h, w) test image in rgb dets1: numpy.ndarray([[x1 y1 x2 y2 score]]) detection results before calibration dets2: numpy.ndarray([[x1 y1 x2 y2 score]]) detection results after calibration thresh: float boxes with scores > thresh will be drawn in red otherwise yellow Returns: ------- """ import matplotlib.pyplot as plt import random import pylab figure = pylab.figure() # plt.subplot(121) pylab.imshow(im_array) figure.suptitle('DFace Detector', fontsize=20) for i in range(dets.shape[0]): bbox = dets[i, :4] rect = pylab.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1], fill=False, edgecolor='yellow', linewidth=0.9) pylab.gca().add_patch(rect) if landmarks is not None: for i in range(landmarks.shape[0]): landmarks_one = landmarks[i, :] landmarks_one = landmarks_one.reshape((5, 2)) for j in range(5): # pylab.scatter(landmarks_one[j, 0], landmarks_one[j, 1], c='yellow', linewidths=0.1, marker='x', s=5) cir1 = Circle(xy=(landmarks_one[j, 0], landmarks_one[j, 1]), radius=2, alpha=0.4, color="red") pylab.gca().add_patch(cir1) # plt.gca().text(bbox[0], bbox[1] - 2, # '{:.3f}'.format(score), # bbox=dict(facecolor='blue', alpha=0.5), fontsize=12, color='white') # else: # rect = plt.Rectangle((bbox[0], bbox[1]), # bbox[2] - bbox[0], # bbox[3] - bbox[1], fill=False, # edgecolor=color, linewidth=0.5) # plt.gca().add_patch(rect) pylab.show()