예제 #1
0
def plotting(sim_context1,sim_context2,diff,data_df,total_samples):

    plt.plot(sim_context1,label="Context 1")
    plt.plot(sim_context2,label="Context 2")


    x_labels_word1 = data_df["word1"]
    x_labels_word2 = data_df["word2"]

    xlabels = [0] * total_samples
    xticks_x = [0] * total_samples


    for wp in range (total_samples):
        xlabels[wp] = x_labels_word1[wp]+ "\n"+x_labels_word2[wp]
        xticks_x[wp] = wp+1

    plt.plot(diff,label="Difference")

    plt.legend(loc='center right')

    # Add title and x, y labels
    plt.title("Elmo Embedding Model Results", fontsize=16, fontweight='bold')

    plt.xlabel("Word")
    plt.ylabel("Similarity")

    plt.xticks(xticks_x, xlabels)
    plt.show()
예제 #2
0
def getGraph():
    for i, clf in enumerate((svm, rbf_svc, rbf_svc_tunning)):
        # Se grafican las fronteras
        plt.subplot(2, 2, i + 1)
        plt.subplots_adjust(wspace=0.4, hspace=0.4)

        Z = clf.predict(np.c_[x_matrizSetEntrenamientoVect, y_clases])

        #Color en las gráficas
        Z = Z.reshape(x_matrizSetEntrenamientoVect.shape)
        plt.contourf(x_matrizSetEntrenamientoVect,
                     y_clases,
                     Z,
                     cmap=plt.cm.Paired,
                     alpha=0.8)

        #Puntos de entrenamiento
        plt.scatter(x_matrizSetEntrenamientoVect[:, 0],
                    x_matrizSetEntrenamientoVect[:, 1],
                    c=y_clases,
                    cmap=plt.cm.Paired)
        plt.xlabel('Longitud Sepal')
        plt.ylabel('Peso Sepal')
        plt.xlim(x_matrizSetEntrenamientoVect.min(),
                 x_matrizSetEntrenamientoVect.max())
        plt.ylim(y_clases.min(), y_clases.max())
        plt.xticks(())
        plt.yticks(())
        plt.title(titles[i])

    plt.show()
def plot():
    plt.figure(figsize=(20, 10))
    width = 0.5
    index = np.arange(26)

    print 'SUM PLOT 1', sum(row[0] for row in data)
    print 'SUM PLOT 2', sum(row[1] for row in data)
    print 'SUM PLOT 3', sum(row[2] for row in data)

    print data[0]
    
    p0 = plt.bar(index, data[0], width, color='y')  # people
    p1 = plt.bar(index, data[1], width, color='g')  # nature
    p2 = plt.bar(index, data[2], width, color='r')  # activity
    p3 = plt.bar(index, data[3], width, color='b')  # food
    p4 = plt.bar(index, data[4], width, color='c')  # symbols
    p5 = plt.bar(index, data[5], width, color='m')  # objects
    p6 = plt.bar(index, data[6], width, color='k')  # flags
    p7 = plt.bar(index, data[7], width, color='w')  # uncategorized


    plt.ylabel('Usage')
    plt.title('Emoji category usage per city')
    plt.xticks(index + width/2.0, cities)
    plt.yticks(np.arange(0, 1, 0.1))
    plt.legend((p0[0], p1[0], p2[0], p3[0], p4[0], p5[0], p6[0], p7[0]), categories_names)

    plt.show()
예제 #4
0
def test_psv_dataset_tfm_segmentation_cropped():
    from psv.ptdataset import PsvDataset, TFM_SEGMENTATION_CROPPED

    ds = PsvDataset(transform=TFM_SEGMENTATION_CROPPED)

    assert len(ds) == 956, "The dataset should have this many entries"

    mb = ds[0]
    image = mb['image']
    mask = mb['mask']
    assert isinstance(image, torch.Tensor)
    assert isinstance(mask, torch.Tensor)

    assert mask.shape[-2:] == image.shape[-2:]

    # Hard to test due to randomness....

    PLOT=True
    if PLOT:
        from matplotlib.pylab import plt
        import torchvision.transforms.functional as F
        a = ds.get_annotation(0)
        plt.figure()
        plt.suptitle('Visualizing test_psv_dataset_tfm_segmentation_cropped, close if ok')
        plt.subplot(121)
        plt.imshow(F.to_pil_image(image))
        plt.title('image')

        plt.subplot(122)
        plt.imshow(a.colors[mask.numpy()])
        plt.title('mask')
        plt.show()
def plot_first_factors(X_data, y_data, analysis_type="lda"):
    """Generate scatterplot of two principal components (pca or lda) of data set."""
    le = preprocessing.LabelEncoder()
    le.fit(y_data)
    colours = [
        'blue', 'green', 'red', 'cyan', 'magenta', 'yellow', 'darkgreen',
        'darkorange', 'yellow', 'black'
    ]
    if analysis_type == "pca":
        transform = PCA(n_components=2)
        XX_data = transform.fit(X_data).transform(X_data)
    elif analysis_type == "lda":
        transform = LinearDiscriminantAnalysis(n_components=2)
        XX_data = transform.fit(X_data, y_data).transform(X_data)
    else:
        print("Type", analysis_type,
              "not recognised, use either 'pca' or 'lda'.")
        return
    plt.figure()
    for i, j in enumerate(le.classes_):
        plt.scatter(XX_data[y_data == j, 0],
                    XX_data[y_data == j, 1],
                    alpha=0.8,
                    color=colours[i],
                    label=str(j))
    plt.legend(loc='best', shadow=False, scatterpoints=1)
    plt.title(analysis_type)
def graph(train_df, test_df, p_forecast, f_forecast, metric, key):
	fig = plt.figure(figsize=(40,10))
	forecast_ds = np.array(f_forecast["ds"])
	print(len(forecast_ds))
	print(len(train_df))
	forecast_ds = forecast_ds[int(train_df["values"].count()):]


	plt.plot(np.array(train_df["ds"]), np.array(train_df["y"]),'b', label="train", linewidth=3)
	plt.plot(np.array(test_df["ds"]), np.array(test_df["y"]), 'k', label="test", linewidth=3)

	plt.savefig( "../testing/compare_fourier_prophet/" + str(key) + "_raw_" + metric + ".png", transparent=True)
	prophet = np.array(p_forecast["yhat"])
	prophet_upper = np.array(p_forecast["yhat_upper"])
	prophet_lower = np.array(p_forecast["yhat_lower"])

	fourier = f_forecast["yhat"]
	fourier = fourier[len(train_df["values"]):]
	print(len(forecast_ds))
	print(len(fourier))
	plt.plot(forecast_ds, fourier, 'g', label="fourier_yhat", linewidth=3)
	plt.savefig( "../testing/compare_fourier_prophet/" + str(key) + "_fourier_" + metric + ".png", transparent=True)

	prophet = prophet[len(train_df["values"]):]
	prophet_upper = prophet_upper[len(train_df["values"]):]
	prophet_lower = prophet_lower[len(train_df["values"]):]
	plt.plot(forecast_ds, prophet, '*y', label="prophet_yhat", linewidth=3)
	plt.plot(forecast_ds, prophet_upper, 'y', label="yhat_upper", linewidth=3)
	plt.plot(forecast_ds, prophet_lower, 'y', label="yhat_lower", linewidth=3)
	
	
	plt.plot()
	plt.xlabel("Timestamp")
	plt.ylabel("Value")
	plt.legend(loc=1)
	plt.title("Prophet Model Forecast")
	plt.savefig( "../testing/compare_fourier_prophet/" + str(key) + "_compare_" + metric + ".png", transparent=True)
	plt.close()


	fig = plt.figure(figsize=(40,10))
	forecast_ds = np.array(f_forecast["ds"])
	forecast_ds = forecast_ds[len(train_df["values"]):]


	plt.plot(np.array(train_df["ds"]), np.array(train_df["y"]),'b', label="train", linewidth=3)
	plt.plot(np.array(test_df["ds"]), np.array(test_df["y"]), 'k', label="test", linewidth=3)

	prophet = np.array(p_forecast["yhat"])
	prophet_upper = np.array(p_forecast["yhat_upper"])
	prophet_lower = np.array(p_forecast["yhat_lower"])
	prophet = prophet[len(train_df["values"]):]
	prophet_upper = prophet_upper[len(train_df["values"]):]
	prophet_lower = prophet_lower[len(train_df["values"]):]
	plt.plot(forecast_ds, prophet, '*y', label="prophet_yhat", linewidth=3)
	plt.plot(forecast_ds, prophet_upper, 'y', label="yhat_upper", linewidth=3)
	plt.plot(forecast_ds, prophet_lower, 'y', label="yhat_lower", linewidth=3)
	plt.savefig( "../testing/compare_fourier_prophet/" + str(key) + "_prophet_" + metric + ".png", transparent=True)
	plt.close()
예제 #7
0
 def plot_error(self, train_errors):
     n = len(train_errors)
     training, = plt.plot(range(n), train_errors, label="Training Error")
     plt.legend(handles=[training])
     plt.title("Error Plot")
     plt.ylabel('Error')
     plt.xlabel('Iterations')
     plt.show()
예제 #8
0
def test_psv_dataset_crop_and_pad():
    import psv.ptdataset as P


    TFM_SEGMENTATION_CROPPED = psv.transforms.Compose(
        psv.transforms.ToSegmentation(),

        # Crop in on the facades
        psv.transforms.SetCropToFacades(pad=20, pad_units='percent', skip_unlabeled=True, minsize=(512, 512)),
        psv.transforms.ApplyCrop('image'),
        psv.transforms.ApplyCrop('mask'),
        
        # Resize the height to fit in the net (with some wiggle room)
        # THIS is the test case -- the crops will not usually fit anymore
        psv.transforms.Resize('image', height=400),
        psv.transforms.Resize('mask', height=400, interpolation=P.Image.NEAREST),

        # Reandomly choose a subimage
        psv.transforms.SetRandomCrop(512, 512),
        psv.transforms.ApplyCrop('image'),
        psv.transforms.ApplyCrop('mask', fill=24), # 24 should be unlabeled
        
        psv.transforms.DropKey('annotation'),
        psv.transforms.ToTensor('image'),
        psv.transforms.ToTensor('mask', preserve_range=True),
        ) 

    ds = P.PsvDataset(transform=TFM_SEGMENTATION_CROPPED)

    assert len(ds) == 956, "The dataset should have this many entries"

    mb = ds[0]
    image = mb['image']
    mask = mb['mask']
    assert isinstance(image, torch.Tensor)
    assert isinstance(mask, torch.Tensor)

    assert mask.shape[-2:] == image.shape[-2:]

    # Hard to test due to randomness....

    PLOT=True
    if PLOT:
        from matplotlib.pylab import plt
        import torchvision.transforms.functional as F
        a = ds.get_annotation(0)
        plt.figure()
        plt.suptitle('Visualizing test_psv_dataset_tfm_segmentation_cropped,\n'
                     'close if ok \n '
                     'confirm boundary is  marked unlabeled')
        plt.subplot(121)
        plt.imshow(F.to_pil_image(image))
        plt.title('image')

        plt.subplot(122)
        plt.imshow(a.colors[mask.numpy()])
        plt.title('mask')
        plt.show()
def display_digit(X_data, y_data=None, i=0):
    """Display the Xi image, optionally with the corresponding yi label."""
    plt.close('all')
    Xi = X_data[i]
    side = np.sqrt(Xi.size).astype(int)
    data = np.array(Xi).reshape((side, side))
    plt.imshow(data, cmap='Greys', interpolation='nearest')
    plt.title("y = " + str(y_data[i]))
    plt.show()
예제 #10
0
 def plot_accuracy(self, train_acc, test_acc):
     n = len(train_acc)
     plt.plot(range(n), train_acc, label="train")
     plt.plot(range(n), test_acc, label="test")
     plt.legend(loc='lower right')
     plt.title("Overfit")
     plt.ylabel('accuracy')
     plt.xlabel('epoch')
     plt.show()
예제 #11
0
 def plot_median_profile():
     # Plot median line profile
     plt.plot(bseg.dw, bseg.s, '.', label='Median Stellar Spectrum')
     plt.plot(bseg.dw, bseg.model, '-', label='Median Telluric Model')
     plt.title('Median Line Profile')
     plt.xlabel('Distance From Line Center (A)')
     yl = list(plt.ylim())
     yl[1] = 1.05
     plt.ylim(*yl)
def plot_gallery(images, titles, h, w, n_row=3,n_col=4):
    plt.figure(figsize=(1.8*n_col, 2.4*n_row))
    plt.subplots_adjust(bottom=0,left=.01,right=.99,top=.90,hspace=.35)
    for i in range(n_row * n_col):
        plt.subplot(n_row,n_col,i+1)
        plt.imshow(images[i].reshape(h,w),cmap=plt.cm.gray)
        plt.title(titles[i],size=12)
        plt.xticks(())
        plt.yticks(())
예제 #13
0
 def plot_median_profile():
     # Plot median line profile
     plt.plot(bseg.dw,bseg.s,'.',label='Median Stellar Spectrum')
     plt.plot(bseg.dw,bseg.model,'-',label='Median Telluric Model')
     plt.title('Median Line Profile')
     plt.xlabel('Distance From Line Center (A)')
     yl = list(plt.ylim())
     yl[1] = 1.05
     plt.ylim(*yl)
예제 #14
0
def Test2():
    t = np.linspace(0,10,100)
    x = np.sin(t)

    plt.plot(t, x)
    plt.title('sin(x)')
    plt.xlabel('time (s)')
    plt.ylabel('magnitude')
    plt.show()
예제 #15
0
 def plot_spectrum():
     # Plot telluric lines and fits
     plt.plot(spec['w'], spec['s'], label='Stellar Spectrum')
     plt.plot(spec['w'], mod, label='Telluric Model')
     plt.plot(spec['w'], spec['s'] - mod + 0.5, label='Residuals')
     plt.xlim(6275, 6305)
     plt.ylim(0.0, 1.05)
     plt.xlabel('Wavelength (A)')
     plt.ylabel('Intensity')
     plt.title('Telluric Lines')
예제 #16
0
 def plot_spectrum():
     # Plot telluric lines and fits
     plt.plot(spec['w'],spec['s'],label='Stellar Spectrum')
     plt.plot(spec['w'],mod,label='Telluric Model')
     plt.plot(spec['w'],spec['s']-mod+0.5,label='Residuals')
     plt.xlim(6275,6305)
     plt.ylim(0.0,1.05)
     plt.xlabel('Wavelength (A)')
     plt.ylabel('Intensity')
     plt.title('Telluric Lines')
예제 #17
0
    def plotting(self, pressurelattice, invasionlattice, pressure,
                 number_of_clusters):

        from matplotlib.pylab import plt

        #Plotting the invasionlattice
        plt.figure(2)
        plt.imshow(invasionlattice, cmap='Greys', interpolation='nearest')
        plt.title("Invasion lattice")
        plt.colorbar()
        plt.savefig(self.pathsimulation + "invasionlattice.png",
                    bbox_inches="tight")
        plt.close()

        #plotting the pressure
        plt.figure(5)
        plt.plot(pressure)
        plt.xlabel('Time')
        plt.ylabel('Pressure')
        plt.title('P(t)')
        plt.savefig(self.pathsimulation + "pressure.png", bbox_inches="tight")
        plt.close()

        #plotting the clusterlattice
        plt.figure(6)
        plt.imshow(self.lw, interpolation='nearest')
        plt.title("Clusterlattice")
        plt.colorbar()
        plt.savefig(self.pathsimulation + "clusterlattice.png",
                    bbox_inches="tight")
        plt.close()

        #Temporal diagram
        plt.figure(7)
        plt.imshow(self.temporalplot, interpolation='nearest')
        plt.title('Temporal diagram')
        plt.colorbar()
        plt.savefig(self.pathsimulation + "temporal.png", bbox_inches="tight")
        plt.close()

        #Plotting pressure distribution in the cell.
        plt.figure(3)
        plt.hist(pressurelattice.ravel(), bins=30, fc='k', ec='k')
        plt.savefig(self.pathsimulation + "pressuredistribution.png",
                    bbox_inches="tight")
        plt.close()

        #Plotting the number of clusters as a function of interation.
        plt.figure(1)
        plt.plot(number_of_clusters)
        plt.xlabel('Iteration number/time')
        plt.ylabel('Number of clusters')
        plt.title('Number_of_cluster(t)')
        plt.savefig(self.pathsimulation + "clusterN.png", bbox_inches="tight")
        plt.close()
예제 #18
0
def plot(ranks):
    plt.figure(figsize=(20, 10))
    plt.title("A2.3 PageRank (s-Sensibility)")
    plt.xlabel("Node ID")
    plt.ylabel("Pagerank")
    for row in ranks:
        plt.plot(row)

    plt.legend(['s = %.2f' % s for s in numpy.arange(0.0, 1.0, 0.05)],
               loc='upper right',
               prop={'size': 7})
    plt.savefig("submission/pagerank.png")
예제 #19
0
    def _build_plot_static(self, metric_group):
        metrics = self.get_metrics_history()
        if metric_group not in metrics:
            raise ValueError("can't find metric group")
        for name, values in metrics[metric_group].items():
            plt.plot(values, label=name)
        plt.legend(loc='best')
        plt.title(metric_group, fontsize=16, fontweight='bold')
        plt.xlabel("Generations")
        plt.show()

        return None
예제 #20
0
파일: MRIpy.py 프로젝트: michaelmendoza/MRI
    def saveMagPhaseImage(self, image, filename):
        mag = absolute(image).astype('float')
        phase = angle(image).astype('float')

        plt.subplot(211)
        plt.imshow(mag, cmap=cm.Greys_r)
        plt.title('Magnitude')
        plt.axis('off')
        plt.subplot(212)
        plt.imshow(phase, cmap=cm.Greys_r)
        plt.title('Phase')
        plt.axis('off')
        plt.savefig(filename)
예제 #21
0
def visual_update_analysis(
    df: pd.DataFrame
) -> Tuple[Dict[str, str], List[Dict[str, Union[str, float]]]]:
    summary = []
    template_vars = {}
    df = df.rename(columns={'date': 'ds'})
    if 'asa_impressions' in df.columns:
        df['impressions'] = df['search_impressions'] - df['asa_impressions']
        df['conversions'] = df['search_downloads'] - df['asa']
    else:
        df['impressions'] = df['search_impressions']
        df['conversions'] = df['search_downloads']
    df['y'] = df['conversions'] / df['impressions']
    df.index = df['ds']

    if options.weekly:
        df = df.resample('W').apply(safe_mean)

    df = handle_outliers(df.copy())

    time_regressors = []
    for _, row in df.iterrows():
        if row['update'] == 'visual' or row['update'] == 'all':
            additional_regressor = '{} (visual)'.format(
                str(row['ds']).split(" ")[0])
            df[additional_regressor] = [
                1 if other_row['ds'] >= row['ds'] else 0
                for _, other_row in df.iterrows()
            ]
            time_regressors.append(additional_regressor)

    model = create_model('sherlock_visual', df, 1.0, False, time_regressors)
    conversion_model = fit_beta_regression(model, df)

    fig = plot_nowcast(conversion_model, [
        row['ds'] for _, row in df.iterrows()
        if row['update'] == 'visual' or row['update'] == 'all'
    ])
    plt.title('Conversion & Visual Updates')
    template_vars['visual_model'] = figure_to_base64(fig)

    summary.extend(
        summary_from_model_regressors(conversion_model, time_regressors))
    seasonality = {}
    for period, fig in plot_seasonality(conversion_model,
                                        alpha=options.alpha,
                                        plot_kwargs={}).items():
        seasonality[int(period)] = figure_to_base64(fig)
    template_vars['conversion_seasonality'] = seasonality

    return template_vars, summary
예제 #22
0
	def plotting(self,pressurelattice,invasionlattice,pressure,number_of_clusters):

		from matplotlib.pylab import plt

		#Plotting the invasionlattice
		plt.figure(2)
		plt.imshow(invasionlattice, cmap='Greys',interpolation='nearest')
		plt.title("Invasion lattice")
		plt.colorbar()
		plt.savefig(self.pathsimulation + "invasionlattice.png", bbox_inches="tight")
		plt.close()

		#plotting the pressure
		plt.figure(5)
		plt.plot(pressure)
		plt.xlabel('Time')
		plt.ylabel('Pressure')
		plt.title('P(t)')
		plt.savefig(self.pathsimulation +"pressure.png", bbox_inches="tight")
		plt.close()

		#plotting the clusterlattice
		plt.figure(6)
		plt.imshow(self.lw, interpolation='nearest')
		plt.title("Clusterlattice")
		plt.colorbar()
		plt.savefig(self.pathsimulation +"clusterlattice.png", bbox_inches="tight")
		plt.close()

		#Temporal diagram
		plt.figure(7)
		plt.imshow(self.temporalplot,interpolation='nearest')
		plt.title('Temporal diagram')
		plt.colorbar()
		plt.savefig(self.pathsimulation +"temporal.png", bbox_inches="tight")
		plt.close()

		#Plotting pressure distribution in the cell.
		plt.figure(3)
		plt.hist(pressurelattice.ravel(), bins=30, fc='k', ec='k')
		plt.savefig(self.pathsimulation +"pressuredistribution.png", bbox_inches="tight")
		plt.close()

		#Plotting the number of clusters as a function of interation.
		plt.figure(1)
		plt.plot(number_of_clusters)
		plt.xlabel('Iteration number/time')
		plt.ylabel('Number of clusters')
		plt.title('Number_of_cluster(t)')
		plt.savefig(self.pathsimulation +"clusterN.png", bbox_inches="tight")
		plt.close()
예제 #23
0
def random_tensor(shape=None,
                  sparsity=0.5,
                  seed=1234,
                  distributed='normal',
                  normal=None,
                  uniform=None,
                  plot=True):
    np.random.seed(seed)
    tensor_size = prod(shape)
    if distributed == 'normal':
        mean, std = normal
        data = np.random.normal(mean, std, tensor_size)

        if plot == True:
            n, bins, patches = plt.hist(data,
                                        30,
                                        normed=True,
                                        facecolor='blue',
                                        alpha=0.5)
            y = mlab.normpdf(bins, mean, std)
            plt.plot(bins, y, 'r--')
            plt.xlabel('Expectation')
            plt.ylabel('Probability')
            plt.title('Histogram of Normal Distribution:$\mu =' + str(mean) +
                      '$, $\sigma=' + str(std) + '$')
            plt.axvline(norm.ppf(sparsity) * std + mean)
            plt.show()

        data[data <= norm.ppf(sparsity) * std + mean] = 0

    if distributed == 'uniform':
        low, high = uniform
        data = np.random.uniform(low, high, size=tensor_size)

        if plot == True:
            n, bins, patches = plt.hist(data,
                                        30,
                                        normed=True,
                                        facecolor='blue',
                                        alpha=0.5)
            plt.xlabel('Expectation')
            plt.ylabel('Probability')
            plt.title('Histogram of Uniform Distribution:$low =' + str(low) +
                      '$, $high =' + str(high) + '$')
            plt.axvline((high - low) * sparsity)
            plt.show()

        data[data <= (high - low) * sparsity] = 0

    return tensor(data.reshape(shape))
예제 #24
0
def plot_average(collected_results, versions, args, plot_std=True):
    test_type = args.test_type
    model_name = args.model

    means, stds = [], []
    for version in versions:
        data = collected_results[version]
        if (plot_std):
            means.append(np.mean(data))
            stds.append(np.std(data))
        else:
            means.append(data)

    means = np.array(means)
    stds = np.array(stds)
    if (test_type == "size" or test_type == "allsize"):
        x = ["0%", "20%", "40%", "60%", "80%", "100%"]
    elif (test_type == "accdomain" or test_type == "moredomain"):
        x = [0, 1, 2, 3, 4]
    else:
        x = versions

    color = 'blue'
    plt.plot(x, means, color=color)
    if (plot_std):
        plt.fill_between(x,
                         means - stds,
                         means + stds,
                         alpha=0.1,
                         edgecolor=color,
                         facecolor=color,
                         linewidth=1,
                         antialiased=True)

    plt.xticks(np.arange(len(x)), x, fontsize=18)
    plt.yticks(fontsize=18)
    plt.xlabel(XLABELS[test_type], fontsize=18)
    plt.ylabel('average absolute effect size', fontsize=18)
    plt.title("Influence of {} on bias removal \nfor {}".format(
        TITLES[test_type], MODEL_FORMAL_NAMES[model_name]),
              fontsize=18)
    plt.tight_layout()

    plot_path = os.path.join(
        args.eval_results_dir, "plots",
        "{}-{}-avg{}.png".format(model_name, test_type,
                                 "-std" if plot_std else ""))
    plt.savefig(plot_path)
예제 #25
0
파일: MRIpy.py 프로젝트: michaelmendoza/MRI
    def showMagPhasePlot(self, t, x):
        mag = absolute(x)
        phase = angle(x)
    
        plt.subplot(211)
        plt.plot(t, mag)
        plt.ylabel('Magitude')
        plt.title('SSPF Sequence')
        plt.grid(True)

        plt.subplot(212)
        plt.plot(t, phase)
        plt.xlabel('Off-Resonance (Hz)')
        plt.ylabel('Phase')
        plt.grid(True)
        plt.show()
예제 #26
0
파일: MRIpy.py 프로젝트: michaelmendoza/MRI
 def saveMagPhasePlot(self, t, x, filename):
     mag = absolute(x).astype('float')
     phase = angle(x).astype('float')
     
     plt.subplot(211)
     plt.plot(t, mag)
     plt.ylabel('Magitude')
     plt.title('SSPF Sequence')
     plt.grid(True)
     
     plt.subplot(212)
     plt.plot(t, phase)
     plt.xlabel('Off-Resonance (Hz)')
     plt.ylabel('Phase')
     plt.grid(True)
     plt.savefig(filename)
예제 #27
0
def plt_score(history):
    plt.figure()
    plt.plot()
    plt.plot(history.history['acc'])
    plt.plot(history.history['val_acc'])
    plt.title('model accuracy')
    plt.ylabel('accuracy')
    plt.xlabel('epoch')
    plt.legend(['train', 'test'], loc='upper left')
    plt.savefig('acc.png')
    # loss
    plt.figure()
    plt.plot(history.history['loss'])
    plt.plot(history.history['val_loss'])
    plt.title('model loss')
    plt.ylabel('loss')
    plt.xlabel('epoch')
    plt.legend(['train', 'test'], loc='upper left')
    plt.savefig('loss.png')
예제 #28
0
def visualize(img, G, vertices):
    plt.imshow(img, cmap='gray')

    # draw edges by pts
    for (s, e) in G.edges():
        vals = flatten([[v] for v in G[s][e].values()])
        for val in vals:
            ps = val.get('pts', [])
            plt.plot(ps[:, 1], ps[:, 0], 'green')

    # draw node by o
    node, nodes = G.node(), G.nodes
    # deg = G.degree
    # ps = np.array([node[i]['o'] for i in nodes])
    ps = np.array(vertices)
    plt.plot(ps[:, 1], ps[:, 0], 'r.')

    # title and show
    plt.title('Build Graph')
    plt.show()
예제 #29
0
def visualize(img, G, vertices):
    plt.imshow(img, cmap='gray')

    # draw edges by pts
    for (s, e) in G.edges():
        vals = flatten([[v] for v in G[s][e].values()])
        for val in vals:
            ps = val.get('pts', [])
            plt.plot(ps[:, 1], ps[:, 0], 'green')

    # draw node by o
    node, nodes = G.node(), G.nodes
    # deg = G.degree
    # ps = np.array([node[i]['o'] for i in nodes])
    ps = np.array(vertices)
    plt.plot(ps[:, 1], ps[:, 0], 'r.')

    # title and show
    plt.title('Build Graph')
    plt.show()
예제 #30
0
def augmentation_visualize_and_save(config,
                                    images,
                                    images_names,
                                    path,
                                    times: int = 2):
    """
    Visualization of image enhancements.
    :param config: configuration from yaml file.
    :param images: images to be augmented.
    :param images_names: corresponding names of the images.
    :param path: the root where the augmented pictures will be saved.
    :param times: how many times each image getting augmented.
    :return:
    """

    rows = len(images)
    cols = times + 1
    for (index, image), name in zip(enumerate(images), images_names):
        plt.subplot(rows, cols, index * cols + 1)
        plt.axis('off')
        plt.title(name)
        _image = bgr2rgb_using_opencv(image)
        plt.imshow(_image)
        for col in range(1, cols):
            plt.subplot(rows, cols, index * cols + col + 1)
            plt.axis('off')
            plt.title("Augmented NO. " + str(col))
            # augment image
            augmented_image = augment_image_using_imgaug(_image, config)
            plt.imshow(augmented_image)

    # Save the full figure
    isExists = os.path.exists(path)
    if not isExists:
        os.makedirs(path)
    now_time = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
    savefig(os.path.join(path, "%s_Comp.png" % now_time), dpi=600)
    # Clear the current figure
    plt.clf()
    plt.cla()
    plt.close()
예제 #31
0
    def display_populations(self,
                            top_k=10,
                            max_chromosome_len=1024,
                            rounding=None):

        for pop_idx, population in enumerate(self._populations):
            num_chromosomes = min(len(population), top_k)
            heatmap = []
            gene_max = 0
            for cidx, chromosome in enumerate(population):
                genes = []
                for gene in chromosome[:max_chromosome_len]:
                    if isinstance(rounding, type(None)):
                        genes.append(str(gene))
                    elif rounding > 0:
                        genes.append(round(float(gene), rounding))
                    else:
                        genes.append(int(gene))
                    gene_max = max(gene_max, gene)
                heatmap.append(genes)
                if cidx > num_chromosomes:
                    break

            fig, ax = plt.subplots()
            im = ax.imshow(heatmap,
                           interpolation='nearest',
                           cmap="viridis",
                           aspect='auto')

            # gradient bar
            cbar = ax.figure.colorbar(im, ax=ax)
            cbar.ax.set_ylabel('Gene value', rotation=-90, va="bottom")

            plt.title(f'Population - top {num_chromosomes}',
                      fontsize=16,
                      fontweight='bold')
            plt.xlabel("Genes")
            plt.ylabel("Chromosome")
            # fig.tight_layout()
            plt.show()
def bar_graph(category, age_grp, sex, x, y, year=None, country=None):

    plt.figure()
    plt.ylabel('ATE = Y1 - Y0')
    plt.xlabel('Years')
    plt.bar(range(len(x)), x, align='center')
    plt.xticks(range(len(x)), y, rotation='vertical')

    if country:
        plt.title("%s Suicide Rates for WC; %s ages %s" %
                  (country, sex, age_grp))
        name = country + sex + age_grp + '.png'
        # plt.show()
        plt.tight_layout()
        plt.savefig('./graphs/Countries' + '/' + sex + '/' +
                    name.replace(' ', '_'))

    elif year:
        plt.title("Change in Suicide Rates per Country in %s; %s ages %s" %
                  (year, sex, age_grp))
        name = category + sex + str(year) + age_grp + '.png'
        # plt.show()
        plt.tight_layout()
        plt.savefig('./graphs/' + category + '/' + sex + '/' + str(year) +
                    '/' + name.replace(' ', ''))
    else:
        plt.title("Change in Suicide Rates in %s Countries; %s ages %s" %
                  (category, sex, age_grp))
        name = category + sex + age_grp + '.png'
        # plt.show()
        plt.tight_layout()
        plt.savefig('./graphs/' + category + '/' + sex + '/' +
                    name.replace(' ', ''))
예제 #33
0
def print_all_results(collected_results, versions, args):
    test_type = args.test_type
    model_name = args.model

    for test_name in collected_results:
        test_results = collected_results[test_name]
        x, y = [], []
        for version in versions:
            if (version in test_results):
                x.append(version)
                y.append(test_results[version]['mean'])
        plt.plot(x, y, label=test_name)

    plt.xticks(np.arange(len(x)), x)
    plt.xlabel(XLABELS[test_type])
    plt.ylabel('average absolute effect size')
    plt.legend(loc='best')
    plt.title("SEAT effect sizes on {} with {}".format(model_name,
                                                       TITLES[test_type]))
    plot_path = os.path.join(args.eval_results_dir, "plots",
                             "{}-{}.png".format(model_name, test_type))
    plt.savefig(plot_path)
예제 #34
0
def plot_scatter_annotate(data, labels, title):
    plt.figure(figsize=(10, 10))
    assert data.shape[0] == len(labels), 'size mismatch'
    plt.subplots_adjust(bottom=0.1)
    plt.scatter(data[:, 0],
                data[:, 1],
                marker='o',
                s=100,
                cmap=plt.get_cmap('Spectral'))
    plt.title(title)
    for label, x, y in zip(labels, data[:, 0], data[:, 1]):
        plt.annotate(label,
                     xy=(x, y),
                     xytext=(-20, 20),
                     textcoords='offset points',
                     ha='right',
                     va='bottom',
                     bbox=dict(boxstyle='round,pad=0.5',
                               fc='yellow',
                               alpha=0.5),
                     arrowprops=dict(arrowstyle='->',
                                     connectionstyle='arc3,rad=0'))
    plt.show()
예제 #35
0
def getGraph():
    for i, clf in enumerate((svm, rbf_svc, rbf_svc_tunning)):
     # Se grafican las fronteras 
     plt.subplot(2, 2, i + 1)
     plt.subplots_adjust(wspace=0.4, hspace=0.4)
    
     Z = clf.predict(np.c_[x_matrizSetEntrenamientoVect, y_clases])
    
     #Color en las gráficas
     Z = Z.reshape(x_matrizSetEntrenamientoVect.shape)
     plt.contourf(x_matrizSetEntrenamientoVect, y_clases, Z, cmap=plt.cm.Paired, alpha=0.8)
    
     #Puntos de entrenamiento
     plt.scatter(x_matrizSetEntrenamientoVect[:, 0], x_matrizSetEntrenamientoVect[:, 1], c=y_clases, cmap=plt.cm.Paired)
     plt.xlabel('Longitud Sepal')
     plt.ylabel('Peso Sepal')
     plt.xlim(x_matrizSetEntrenamientoVect.min(), x_matrizSetEntrenamientoVect.max())
     plt.ylim(y_clases.min(), y_clases.max())
     plt.xticks(())
     plt.yticks(())
     plt.title(titles[i])
    
    plt.show()
예제 #36
0
def plot_result(filename='glances.csv'):
    import pandas as pd
    from matplotlib.pylab import plt
    data = pd.read_csv(filename)
    mem_used = data['mem_used'].apply(lambda x: float(x) / (10**9))

    plt.figure(1)

    plt.subplot(121)
    mem_used.plot(color="r", linestyle="-", linewidth=1)
    plt.xlabel('time step')
    plt.ylabel('GB')
    plt.title('mem_used')

    plt.subplot(122)
    gpu_0_proc = data['gpu_0_proc']
    gpu_0_proc.plot(color="b", linestyle="-", linewidth=1)
    plt.xlabel('time step')
    plt.ylabel('proc')
    plt.title('gpu_0_proc')
    plt.show()

    print("mean mem_used:{},mean_gpu_0_proc:{}".format(mem_used.mean(),
                                                       gpu_0_proc.mean()))
예제 #37
0
    def saveWaterFatImage(self, filename):
        mag = np.absolute(self.water).astype('float')
        phase = np.angle(self.water).astype('float')
        mag2 = np.absolute(self.fat).astype('float')
        phase2 = np.angle(self.fat).astype('float')

        plt.subplot(221)
        plt.imshow(mag, cmap=cm.Greys_r)
        plt.title('Water Magnitude')
        plt.axis('off')
        plt.subplot(222)
        plt.imshow(phase, cmap=cm.Greys_r)
        plt.title('Water Phase')
        plt.axis('off')
        plt.subplot(223)
        plt.imshow(mag2, cmap=cm.Greys_r)
        plt.title('Fat Magnitude')
        plt.axis('off')
        plt.subplot(224)
        plt.imshow(phase2, cmap=cm.Greys_r)
        plt.title('Fat Phase')
        plt.axis('off')
        plt.show()
예제 #38
0
파일: MRIpy.py 프로젝트: michaelmendoza/MRI
    def saveMagPhaseImage2(self, image1, image2, filename):
        mag = absolute(image1).astype('float')
        phase = angle(image1).astype('float')
        mag2 = absolute(image2).astype('float')
        phase2 = angle(image2).astype('float')

        plt.subplot(221)
        plt.imshow(mag, cmap=cm.Greys_r)
        plt.title('Magnitude')
        plt.axis('off')
        plt.subplot(222)
        plt.imshow(phase, cmap=cm.Greys_r)
        plt.title('Phase')
        plt.axis('off')
        plt.subplot(223)
        plt.imshow(mag2, cmap=cm.Greys_r)
        plt.title('Magnitude')
        plt.axis('off')
        plt.subplot(224)
        plt.imshow(phase2, cmap=cm.Greys_r)
        plt.title('Phase')
        plt.axis('off')
        plt.savefig(filename)
예제 #39
0
    xls_date = xlrd.xldate_as_tuple(float(index_name), 0)
    year, month, day, hour, minute, second = xls_date
    py_datetime = datetime.datetime(year, month, day, hour, minute, second)
    datetime_str = py_datetime.strftime('%b-%Y') 
    
    return datetime_str
    
emp_data_dir_2013 = 'data/emp_data_2008_2014'
emp_files = get_files_in_directory(emp_data_dir_2013, '.csv')
df_list = []
for csv_file in emp_files:
    pathname = csv_file[0]
    ag_row, header_row = get_csv_row_number(pathname, 'TOTAL AGRICULTURAL')
    df = pd.read_csv(pathname, sep=',', quotechar='"', skiprows=header_row-1, index_col=1, header=0)
    df_list.append(df)
pertinent_dfs = []
for df in df_list:
    columns_not_of_interest = ['NAICS CODES', 'TITLE']
    df_columns = list(df.columns.values)
    column_list = [column for column in df_columns if column not in columns_not_of_interest]
    df_pert_dirty = df[column_list]
    df_clean = df_pert_dirty.loc['TOTAL AGRICULTURAL', :]
    df_clean_reindex = df_clean.rename(rename_index)
    print(df_clean_reindex)
    pertinent_dfs.append(df_clean_reindex)
s_concat = pd.concat(pertinent_dfs)
s_concat.plot(kind='bar')
plt.title('CA Agricultural Employment')
plt.xlabel('Month')
plt.ylabel('Agricultural Employment')
plt.show()
예제 #40
0
            plt.plot(x, y, label="N={}".format(k))
    return x, y


def exact():
    W = Lea.fastMax(W0 + U, 0)
    for k in range(1, 21):
        if k % 5 == 0:
            plt.plot(W.support(), W.pmf(), label="k={}".format(k))
        W = Lea.fastMax(W + U, 0)
    return W.support(), W.pmf()


plt.figure()
plt.axis([0, 20, 0, 0.3])
plt.title("Exact")
xex, yex = exact()
plt.legend()
tikz_save('waiting_time_1.tex', figureheight='5cm', figurewidth='5cm')
plt.close()

plt.figure()
plt.axis([0, 20, 0, 0.3])
plt.title("Simulation")
xsim, ysim = simulate()
plt.legend()
tikz_save('waiting_time_2.tex', figureheight='5cm', figurewidth='5cm')
plt.close()

plt.figure()
plt.axis([0, 20, 0, 0.3])
예제 #41
0
    a = log(u)
    b = log(1-0.4)
    return int(a / b) + 1


gt = []
for i in range(10**4):
    gt.append(geo())
#print gt
x = [g1,g2,g3,gt]
common_params =dict(bins=35, normed=1,histtype='bar', alpha=0.7,range=(0,18), color=['blue','green','red','orange'],align='right',label=['Muestra de 100 Geoms.','Muestra de 1000 Geoms.','Muestra de 10000 Geoms.','Muestra teorica'])

plt.subplots_adjust(hspace=.4)
#plt.title('Skinny shift - 3 at a time')
#plt.hist((g1, g2, g3, gt), **common_params)
#plt.subplot(313)
# 100 Geometricas
#plt.hist(g2, 35,normed=1, facecolor='green',alpha=0.7,width=0.2)
plt.hist(g1, 35,normed=1 , facecolor='b',alpha=0.7,width=0.2)
#plt.hist(gt,35,normed=1,facecolor='grey',alpha=0.6,width=0.2 )
#plt.hist(g3, 35,normed=1, facecolor='b',alpha=0.7,width=0.2)



plt.title('Histograma con 100 variables Aleatorias Geometricas de parametro 0.4')

plt.axvline(np.mean(g1), color='blue', linestyle='dashed', linewidth=2)
#plt.hist(x, **common_params)
#plt.legend()
plt.show()
            emotion: per_emotion_data[emotion][feature]
            for emotion in EMOTIONS
        }
        data = {
            emotion: [convert_to_list(vid) for vid in data[emotion]]
            for emotion in EMOTIONS
        }
        data = {emotion: np.array(data[emotion]) for emotion in EMOTIONS}

        for emotion in EMOTIONS:
            print(emotion)
            print("Plotting for emotion " + emotion)
            emotion_data = data[emotion]
            for vid in emotion_data:
                plt.plot(np.arange(len(vid)),
                         vid,
                         label=emotion,
                         color=colors[emotion])
        plt.title(feature + " over time for subject " + subject)
        # plt.legend([colors[emotion] for emotion in EMOTIONS], EMOTIONS)
        plt.legend()
        print('Saving plot...')
        if 'Neck/Nose' in feature:
            feature_name = feature.replace('Neck/Nose', 'Neck')
        else:
            feature_name = feature

        plt.savefig(plots_dir + "/" + subject + "/" + feature_name + '.png')
        plt.close()
        print('Done.')
예제 #43
0
# -*- coding:utf-8 -*-
#V:Python 3.6.3
import pandas as pd
from IPython.display import display
from matplotlib.pylab import plt

data = pd.read_csv('house3.csv')
data['total_price'] = data['price'] * data['area'] / 10000

data_mean = data.groupby('district')['price'].mean()
data_count = data.groupby('district')['price'].count()

#柱状图分析各区的二手房的房价
plt.figure(figsize=(10, 6))
plt.rc('font', family='SimHei', size=13)
plt.title(u'各区域的平均二手房房价')
plt.xlabel(u'南京城区')
plt.ylabel(u'平均房价')
plt.bar(data_mean.index, data_count.values, color='g')
plt.show()

plt.figure(figsize=(10, 10))
plt.rc('font', family='SimHei', size=13)
explode = [0] * len(data_count)
explode[9] = 0.1
plt.pie(data_count,
        radius=2,
        autopct='%1.f%%',
        shadow=True,
        labels=data_mean.index,
        explode=explode)
예제 #44
0
    t_tuple = (TOMATOES, 'tomatoes')
    lemon_tuple = (LEMONS, 'lemons')
    tuple_list = [o_tuple, g_tuple, b_tuple, s_tuple, lettuce_tuple, t_tuple, lemon_tuple]
    csv_paths = []
    for produce_tuple in tuple_list:
        filepath, produce_item = produce_tuple
        csv_path = 'data\\produce\\{0}.csv'.format(produce_item)
        csv_paths.append((csv_path, produce_item))
        excel_to_csv(filepath, csv_path)
    dfs = {}
    for csv_tuple in csv_paths:
        csv_path, produce_item = csv_tuple
        df = pd.read_csv(csv_path, sep=',', quotechar='"', skiprows=8, header=0, index_col=0)
        df1 = df.loc[2010:]
        dfs[produce_item] = df1
    for key in dfs:
        produce_df = dfs[key]
        produce_df_stacked = produce_df.stack()
        produce_df_stacked.plot(kind='bar', color='c')
        title = '{0} CPI'.format(key)
        y_label = '{0} Average Price/lb'.format(key)
        x_label = 'Month'
        plt.title(title)
        plt.ylabel(y_label)
        plt.xlabel(x_label)
        fig = gcf()
        fig.set_size_inches(18.5, 14.5)
        figure_name = 'plots\\{0}.png'.format(key)
        fig.savefig(figure_name)
    
예제 #45
0
    def plot(self, **kwargs):
        """A wrapper function for plotting a NetworkX graph

        This function will draw a provided NetworkX graph using either the
        spring layout algorithm, or by the positions provided.

        Parameters
        ----------
        pos: dict, optional, default: networkx.drawing.layout.spring_layout
            A dictionary of the network's neurons as keys and their (x, y)
            coordinates as corresponding values.

        nodelist: list, optional, default: self.neurons
            Draw only specified neurons (nodes).

        node_size: int or list, optional, default: 300
            The size of the plotted neurons in the network.

        node_color: (color string, or array of floats), optional, default: 'r'
            Can either be a single color format string (default=’r’), or a
            sequence of colors with the same length as nodelist. If numeric
            values are specified they will be mapped to colors using the
            cmap and vmin, vmax parameters. See matplotlib.scatter for more
            details.

        cmap: Matplotlib colormap, optional, default: None
            Colormap for mapping intensities of nodes.

        alpha: float, optional, default: 1.0
            The transparency of the nodes.

        node_borders: (None, scalar, or sequence), optional, default: 'black'
            The color(s) of the node borders.

        edgelist: (collection of edge tuples), optional, default: self.connections
            Draw only specified edges. By default, the edges between all
            nodes will be drawn. If `[]` (i.e. empty list), then the edges
            between all nodes will be omitted from the figure.

        edge_alpha: float, optional, default is 1.0
            The transparency of the edges.

        edge_color: (color string, or array of floats), default: 'r'
            Can either be a single color format string, or a sequence of
            colors with the same length as edgelist. If numeric values are
            specified they will be mapped to colors using the edge_cmap and
            edge_vmin, edge_vmax parameters.

        edge_cmap : Matplotlib colormap, optional, default: None
            Colormap for mapping intensities of edges.

        width: float, optional, default: 1.0
            The width of the edges.

        labels: bool, optional, default: True
            If False, then omit node labels and edge labels.

        font_size: int, optional, default: 10
            The size of the font for text labels.

        figsize: tuple, optional, default: (20, 20)
            The size of the network figure to be plotted.

        savefig: bool, optional, default: False
            When True, the plotted figure will be saved to the current
            working directory, in PDF format, at the default (or specified)
            DPI.

        dpi: int, optional, default: 600
            The amount of dots per inch to use when saving the figure. In
            accordance with Nature's guidelines, the default is 600.
            Source: https://www.nature.com/nature/for-authors/final-submission

        title: str, optional, default: None
            The title of the plotted graph/network.

        Returns
        -------
        pos: dict
            A dictionary of the network's neurons as keys and their (x, y)
            coordinates as corresponding values.
        """

        # Get positions for all nodes
        pos = kwargs.get("pos", None)
        if pos is None:
            print(
                "A neuron position dictionary was not provided! The spring_layout function will be used to plot the network.",
                file=sys.stderr)
            pos = nx.spring_layout(self.network, weight="weight")

        # Size of the plot
        plt.figure(figsize=kwargs.get("figsize", (20, 20)))

        # Nodes
        cmap = kwargs.get("cmap", None)
        alpha = kwargs.get("alpha", 1.0)
        node_size = kwargs.get("node_size", 600)
        nodelist = kwargs.get("nodelist", self.neurons)
        node_color = kwargs.get("node_color", 'r')
        node_borders = kwargs.get("node_borders", "black")
        nx.draw_networkx_nodes(self.network,
                               pos,
                               nodelist=nodelist,
                               alpha=alpha,
                               node_size=node_size,
                               cmap=cmap,
                               node_color=node_color,
                               edgecolors=node_borders)

        # Draw edges
        width = kwargs.get("width", 1.0)
        edge_alpha = kwargs.get("edge_alpha", 1.0)
        edge_color = kwargs.get("edge_color", 'r')
        edge_cmap = kwargs.get("edge_cmap", None)
        edgelist = kwargs.get("edgelist", self.connections)
        nx.draw_networkx_edges(self.network,
                               pos,
                               edgelist=edgelist,
                               alpha=edge_alpha,
                               width=width,
                               edge_color=edge_color,
                               edge_cmap=edge_cmap)

        # Draw labels
        if kwargs.get("labels", True):
            nx.draw_networkx_labels(self.network,
                                    pos,
                                    font_size=kwargs.get("font_size", 10))

        plt.title(kwargs.get("title", None))
        plt.axis("off")

        if kwargs.get("savefig", False):
            plt.savefig(kwargs.get("title", "my_neuron_network.pdf"),
                        format="pdf",
                        dpi=kwargs.get("dpi", 600))

        plt.show()

        return pos
예제 #46
0
    }

    new_controller('example_configuration.cnf', 'example_controller.py', 'PIDAW', param)

    # Create a motor object for simulation
    motor = DC_Motor(configfile='model.cnf', controlmodule='example_controller')

    # Simulate the system with an alternating step reference 
    ref, u, x, y = motor.simulate(30, 'steps')

    # Visualize simulation
    t = np.array([ii * motor.h for ii in range(len(u[0,:]))])
    plt.figure(1);
    plt.step(t, u[0])
    limits = np.array(plt.axis())*np.array([1.,1.,1.1,1.1])
    plt.axis(limits)
    plt.title('Control signal(s)')

    plt.figure(2);
    plt.step(t, np.transpose(x))
    limits = np.array(plt.axis())*np.array([1.,1.,1.1,1.1])
    plt.axis(limits)
    plt.title('System states')

    plt.figure(3);
    plt.step(t, ref[0])
    plt.step(t, x[0])
    limits = np.array(plt.axis())*np.array([1.,1.,1.1,1.1])
    plt.axis(limits)
    plt.title('Theta and reference')
    plt.show()