Example #1
0
def calibration_plot(prob, ytest):
    # stolen from stackoverflow!
    outcome = ytest
    data = pd.DataFrame(dict(prob=prob, outcome=outcome))

    #group outcomes into bins of similar probability
    bins = np.linspace(0, 1, 20)
    cuts = pd.cut(prob, bins)
    binwidth = bins[1] - bins[0]
    
    #freshness ratio and number of examples in each bin
    cal = data.groupby(cuts).outcome.agg(['mean', 'count'])
    cal['pmid'] = (bins[:-1] + bins[1:]) / 2
    cal['sig'] = np.sqrt(cal.pmid * (1 - cal.pmid) / cal['count'])
        
    #the calibration plot
    ax = plt.subplot2grid((3, 1), (0, 0), rowspan=2)
    p = plt.errorbar(cal.pmid, cal['mean'], cal['sig'])
    plt.plot(cal.pmid, cal.pmid, linestyle='--', lw=1, color='k')
    plt.ylabel("Empirical P(Product)")
    
    #the distribution of P(fresh)
    ax = plt.subplot2grid((3, 1), (2, 0), sharex=ax)
    
    plt.bar(left=cal.pmid - binwidth / 2, height=cal['count'],
            width=.95 * (bins[1] - bins[0]),
            fc=p[0].get_color())
    
    plt.xlabel("Predicted P(Product)")
    plt.ylabel("Number")
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()
Example #3
0
    def show(self, w):
        """
        illustrate the learning curve

        Parameters
        ----------
        w : int, window size for smoothing the curve
        """

        # plot data
        plt.subplot(121)
        plt.plot(self.tn_it, self.tn_err, 'b.', alpha=0.2)
        plt.plot(self.tt_it, self.tt_err, 'r.', alpha=0.2)
        # plot smoothed line
        xne,yne = self._smooth( self.tn_it, self.tn_err, w )
        xte,yte = self._smooth( self.tt_it, self.tt_err, w )
        plt.plot(xne, yne, 'b')
        plt.plot(xte, yte, 'r')
        plt.xlabel('iteration'), plt.ylabel('cost energy')

        plt.subplot(122)
        plt.plot(self.tn_it, self.tn_cls, 'b.', alpha=0.2)
        plt.plot(self.tt_it, self.tt_cls, 'r.', alpha=0.2)
        # plot smoothed line
        xnc, ync = self._smooth( self.tn_it, self.tn_cls, w )
        xtc, ytc = self._smooth( self.tt_it, self.tt_cls, w )
        plt.plot(xnc, ync, 'b', label='train')
        plt.plot(xtc, ytc, 'r', label='test')
        plt.xlabel('iteration'), plt.ylabel( 'classification error' )
        plt.legend()
        plt.show()
        return
Example #4
0
    def show(self, w):
        """
        illustrate the learning curve

        Parameters
        ----------
        w : int, window size for smoothing the curve
        """

        # plot data
        plt.subplot(121)
        plt.plot(self.tn_it, self.tn_err, 'b.', alpha=0.2)
        plt.plot(self.tt_it, self.tt_err, 'r.', alpha=0.2)
        # plot smoothed line
        xne, yne = self._smooth(self.tn_it, self.tn_err, w)
        xte, yte = self._smooth(self.tt_it, self.tt_err, w)
        plt.plot(xne, yne, 'b')
        plt.plot(xte, yte, 'r')
        plt.xlabel('iteration'), plt.ylabel('cost energy')

        plt.subplot(122)
        plt.plot(self.tn_it, self.tn_cls, 'b.', alpha=0.2)
        plt.plot(self.tt_it, self.tt_cls, 'r.', alpha=0.2)
        # plot smoothed line
        xnc, ync = self._smooth(self.tn_it, self.tn_cls, w)
        xtc, ytc = self._smooth(self.tt_it, self.tt_cls, w)
        plt.plot(xnc, ync, 'b', label='train')
        plt.plot(xtc, ytc, 'r', label='test')
        plt.xlabel('iteration'), plt.ylabel('classification error')
        plt.legend()
        plt.show()
        return
def plot_histogram(entries):
    n, bins, patches = plt.hist(entries.values(), 50, normed=1, facecolor='green', alpha=0.75)

    plt.xlabel('Time (h)')
    plt.ylabel('Probability')
    plt.grid(True)
    plt.show()
Example #6
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()
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()
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(' ', ''))
Example #9
0
def AddRegressor():
    rng = np.random.RandomState(1)  # 和random_state的用法一致   在这可以固定生成的随机数
    x = np.sort(5 * rng.rand(80, 1),
                axis=0)  # rng.rand(80,1)  生成80行1列的随机数 乘以5就是生成0-5的随机数
    y = np.sin(x).ravel()  # ravel()降维
    y[::5] += 0.3 * (0.5 - rng.rand(16))

    # plt.show()
    reg1 = tree.DecisionTreeRegressor(max_depth=2)
    reg2 = tree.DecisionTreeRegressor(max_depth=5)
    reg1.fit(x, y)
    reg2.fit(x, y)

    test = np.arange(0.0, 5.0, 0.01)[:, np.newaxis]
    y1 = reg1.predict(test)
    y2 = reg2.predict(test)
    #plt.figure()
    plt.figure()
    plt.scatter(x, y, label='dian')
    plt.plot(test, y1, color='red', label='max_depth=2')
    plt.plot(test, y2, color='yellow', label="max_depth=5")
    plt.xlabel('data')
    plt.ylabel('target')
    plt.legend(loc='upper right')
    plt.show()
Example #10
0
def compare_MC_exact():
	max_error = []
	sum_error = []
	walkers = []
	for i in range(500,20000,500):
		d1 = Diffusion(t=0.2)
		t_exact,u_exact = d1.exact()
		t_uniform , mc_uniform = d1.MC_uniform(i)
		print len(u_exact)
		print len(mc_uniform)
		diff = u_exact[:] - mc_uniform[:]
		temp = max(abs(diff))
		max_error.append(temp)
		temp = sum(diff)
		sum_error.append(temp)
		temp = i
		print temp
		walkers.append(temp)

	from matplotlib.pylab import plt
	plt.figure(2)	
	plt.plot(walkers,max_error,'o-')
	plt.xlabel('Number of walkers')
	plt.ylabel('Maximum error')
	plt.savefig('mcuniform_error1.eps')

	plt.figure(3)
	plt.plot(walkers,sum_error,'o-')
	plt.xlabel('Number of walkers')
	plt.ylabel('Accumulated error')
	plt.savefig('mcuniform_error2.eps')
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()
 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()
 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()
Example #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()
Example #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')
Example #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')
def multiplot_gen_property_type():
    #
    # font = {'family': 'Liberation Serif',
    #         'weight': 'normal',
    #         'size': 15
    #         }
    #
    # # play around with the font size if it is too big or small
    # matplotlib.rcParams['axes.titlesize'] = 12
    # matplotlib.rcParams['axes.labelsize'] = 12
    # matplotlib.rc('font', **font)
    # # matplotlib.rcParams['text.usetex'] = True
    # matplotlib.rcParams['pdf.fonttype'] = 42
    # matplotlib.rcParams['pdf.use14corefonts'] = True

    x = list(data.keys())

    y1=[]
    y2=[]
    y3=[]
    y4=[]
    y5=[]
    y6=[]
    
    for year in data.keys():
        for option_name, count in data[year].items():
            if option_name == 'domain':
                y1.append(count)
            if option_name == 'sitekey':
                y2.append(count)
            if option_name == 'third-party':
                y3.append(count)
            if option_name == 'websocket':
                y4.append(count)
            if option_name == 'webrtc':
                y5.append(count)
            if option_name == 'csp':
                y6.append(count)
    
                   
    plt.plot(x, y1,'-o',label='domain')
    plt.plot(x, y2,'-v',label='sitekey')
    plt.plot(x, y3,'-^',label='third-party')
    plt.plot(x, y4,'-<',label='websocket')
    plt.plot(x, y5,'->',label='webrtc')
    plt.plot(x, y6,'-1',label='csp')

    plt.xticks(rotation='vertical')
    plt.xlabel('Year')
    plt.ylabel('Count')

    plt.legend(ncol=2)

    plt.tight_layout()
    plt.savefig('easylist-property-type.pdf ', format='pdf', dpi=1200)
Example #18
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()
Example #19
0
def plot_histogram(entries):
    n, bins, patches = plt.hist(entries.values(),
                                50,
                                normed=1,
                                facecolor='green',
                                alpha=0.75)

    plt.xlabel('Time (h)')
    plt.ylabel('Probability')
    plt.grid(True)
    plt.show()
Example #20
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")
Example #21
0
 def plot_graph(self, auroc_results, y_label: str):
     for ad_key, ad_label in AD_NAMES.items():
         plt.plot(self.x_axis,
                  numpy.asarray(auroc_results[ad_key], ),
                  label=ad_label)
     plt.legend(loc='lower left')
     plt.xlabel(self.x_axis_label)
     plt.ylabel(ylabel=y_label)
     to_print = plt.gcf()
     plt.show()
     file_name_with_metric = y_label + "-" + self.file_name
     to_print.savefig(file_name_with_metric, bbox_inches='tight')
Example #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()
Example #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))
Example #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)
Example #25
0
def plot_score_dist(spacing, std_along, prob_miss, max_distance):
    from matplotlib.pylab import plt
    plt.close("Score Dist")
    plt.figure("Score Dist")
    d = np.linspace(0, max_distance, 500)
    plt.plot(d, [score_dist(di, spacing, std_along, prob_miss) for di in d])
    plt.vlines(spacing, 0, 1)
    plt.vlines(spacing * 2, 0, 1, ls='--')
    plt.annotate("Miss-detect the next mine", (spacing * 2, 0.5), (12, 0),
                 textcoords='offset points')
    plt.ylabel('$p(d)$')
    plt.xlabel('$d$')
    plt.grid()
    plt.xticks(np.arange(max_distance))
    plt.xlim(0, max_distance)
    plt.savefig('score_dist.pdf')
Example #26
0
    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()
Example #27
0
 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)
Example #28
0
def plot_piledspectra():
    fig = plt.figure(figsize = (6,8)) 
    plt.xlim(5000,9000)
    
    specindex = range(0,100,10)
    offset = np.arange(0,len(specindex)) * 0.5
    ylim = [0.5, offset[-1] + 1.3]
    plt.ylim(ylim[0], ylim[1])
    
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')
    
    plt.xlabel(r'Restrame Wavelength [ \AA\ ]')
    plt.ylabel(r'Flux')
    
    line_wave = [5175., 5892., 6562.8, 8498., 8542., 8662.] 
        #       ['Mgb', 'NaD', 'Halpha', 'CaT', 'CaT', 'CaT']
    for line in line_wave:
            x = [line, line]
            y = [ylim[0], ylim[1]]
            plt.plot(x, y, c= 'gray', linewidth=1.0)
    
    plt.annotate(r'CaT', xy=(8540.0, ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'H$\alpha$', xy=(6562.8, ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'NaD', xy=(5892., ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'Mg$\beta$', xy=(5175., ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    
    for i,j in zip(specindex,offset):
        iraf.noao.onedspec.continuum(input = GCssorted.ORIGINALFILE.iloc[i] + '[1]', output = '/Volumes/VINCE/OAC/continuum.fits',
            type = 'ratio', naverage = '3', function = 'spline3',
            order = '5', low_reject = '2.0', high_reject = '2.0', niterate = '10')
    
        data = fits.getdata('/Volumes/VINCE/OAC/continuum.fits', 0)
        
        hdu = fits.open(GCssorted.ORIGINALFILE.iloc[i])
        header1 = hdu[1].header
        lamRange = header1['CRVAL1']  + np.array([0., header1['CD1_1'] * (header1['NAXIS1'] - 1)]) 
        wavelength = np.linspace(lamRange[0],lamRange[1], header1['NAXIS1'])
        hdu.close()
    
        zp = 1. + (GCssorted.VREL.iloc[i] / 299792.458)
      
        plt.plot(wavelength/zp, gaussian_filter(data,2) + j, c = 'black', lw=1)
        os.remove('/Volumes/VINCE/OAC/continuum.fits')
Example #29
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')
Example #30
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()
Example #31
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)
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()
Example #33
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()))

lon, lat = np.mgrid[-40:40, -40:40]
T = temp(lon, lat)

sns.set_style("dark")
ax = fig.add_subplot(121)
plt.scatter(x1, y1, color='firebrick', alpha=0.15)
plt.scatter(x2, y2, color='mediumseagreen', alpha=0.15)
plt.scatter(x3, y3, color='goldenrod', alpha=0.15)
plt.scatter(xL, yL, color='navy')
levels = [2.5, 7.5, 12.5, 17.5]
CS = ax.contour(lon,
                lat,
                T,
                levels=[2.5, 7.5, 12.5, 17.5],
                linewidths=1,
                colors='k')
fmt = '%r $^{\circ}$C'
ax.clabel(CS, inline=1, fontsize=10, fmt=fmt, **hfont)
plt.xlabel('$^{\circ}$E', fontsize=18, **hfont)
plt.ylabel('$^{\circ}$N', fontsize=18, **hfont)
ax.tick_params(labelbottom=False, labelleft=False)
plt.title('(a)', fontsize=18, **hfont)
plt.xlim(-40, 40)
plt.ylim(-40, 40)

plt.savefig('/Users/nooteboom/Documents/PhD/firstpaper/articleplots/plots/' +
            'illustration_PDFS.pdf',
            bbox_inches="tight")
plt.show()
Example #35
0
import pandas as pd
import numpy as np
from matplotlib.pylab import plt #load plot library


df = pd.read_csv("../data/well_monthly_2017.csv", header=0)

months = range(1, 13)
for well_i in range(1, 18):
    data_i = df[df["well"] == well_i]
    data_i.drop(columns=["month", "well"], inplace=True)

    data = data_i.values.flatten()
    plt.plot(months, data, label="Well " + str(well_i))
    print("well ", well_i)
plt.legend(loc='top left')
plt.xlabel("Month")
plt.ylabel("Pumped Amount 2017")

plt.show()
Example #36
0
    df_di_produce["mon_int"] = df_di_produce.apply(report_month, axis=1, date_col="date")
    df_di_produce.index = df_di_produce["date"]
    df_di_produce_summer = df_di_produce[
        (df_di_produce["mon_int"] >= 1) & (df_di_produce["mon_int"] <= 12)
    ]  # just get June - August for each year
    print(df_di_produce_summer)
    grouper_year = pd.TimeGrouper("A")
    df_avg = df_di_produce_summer.groupby(grouper_year).mean()
    df_avg["year"] = df_avg.index.year
    df_avg["year_str"] = df_avg.apply(year_str, axis=1, year_col="year")
    pertinent_columns = ["Lemons Avg Price", "Navel_Oranges Avg Price", "Lettuce Avg Price", di_str, "year_str"]
    df_summer_avg = df_avg[pertinent_columns]
    df_summer_avg.plot(
        kind="scatter",
        y=["Lemons Avg Price", "Navel_Oranges Avg Price", "Lettuce Avg Price"],
        x=[di_str] * 3,
        color=["blue", "red", "green"],
        label=["lemon", "orange", "lettuce"],
    )
    title = "Produce Price vs Percent Severe Drought"
    plt.xlabel("Percent of CA experiencing severe drought")
    plt.ylabel("Price (USD/lb)")
    plt.legend(loc="best")
    plt.title(title)
    fig = gcf()
    fig.set_size_inches(18.5, 14.5)
    plot_name = "price_vs_drought_index"
    figure_name = "plots/{0}.png".format(plot_name)
    fig.savefig(figure_name)
    df_summer_avg.to_csv("data/ca_price_vs_pct_severe_di.csv", index=False)
Example #37
0
BergondGCs = Bergond[Bergond['Type'] =='gc']
BergondGCs[['RAJ2000', 'DEJ2000']].to_csv('/Volumes/VINCE/OAC/imaging/BergondGCs_RADEC.reg', index = False, sep =' ', header = None)

cat1 = coords.SkyCoord(GCs['RA_g'], GCs['DEC_g'], unit=(u.degree, u.degree))
cat2 = coords.SkyCoord(BergondGCs['RAJ2000'], BergondGCs['DEJ2000'], unit=(u.degree, u.degree))

index,dist2d, _ = cat1.match_to_catalog_sky(cat2)
mask = dist2d.arcsec < 0.3
new_idx = index[mask]

VIMOS = GCs.ix[mask].reset_index(drop = True)
BergondMatch = BergondGCs.ix[new_idx].reset_index(drop = True)
print len(BergondMatch)

x = VIMOS['VREL_helio'] 
xerr = VIMOS['VERR'] 
y = BergondMatch['HRV'] 
yerr = BergondMatch['e_HRV'] 

plt.errorbar(x, y, yerr= yerr, xerr = xerr, fmt = 'o', c ='red',label = 'Bergond et al.')

plt.rc('text', usetex=True)
plt.rc('font', family='serif')    
plt.xlabel(r'Velocity from this work [km s$^-1$ ]')
plt.ylabel(r'Velocity from the literature [km s$^-1$ ]')
plt.legend(loc = 'upper left')
plt.tight_layout()
plt.show()

print 'rms (VIMOS - Bergond) GCs = ', np.std(x-y)
Example #38
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)
    
Example #39
0
			plt.plot(xdata, ydata, color="red")

			#print(ydata)

			xdata_prev = xdata_prev + 1
			ydata_prev = rvalue
			
		
			

		count = count + 1
	
print('Average probability density: ', p_sum/vector_l)
plt.title('Frequency concentration of '+word_hash)
plt.xlabel('Coordinates of the sequence')
plt.ylabel('K-mer density [0-1] for word '+word_hash)

avg_freq = float(frequency)/float(seq_len)
uniform = 1 / ( 4 ** len(word_hash) )
print('Average frequency distribution: ', avg_freq)
print('Expected uniform distribution: ', uniform)
print('Total accounted for: ', total)

plt.plot([0, vector_l], [avg_freq, avg_freq], color="blue", label='Average frequency distribution')
plt.plot([0, vector_l], [2*avg_freq, 2*avg_freq], color="cyan", label='Average frequency distribution')
plt.plot([0, vector_l], [uniform, uniform], color="orange", label='Uniform distribution')
plt.plot([0, vector_l], [observed_prob, observed_prob], color="green", label='Observed probability')
leg = axes.legend()


plt.savefig(filepath+'.png')
Example #40
0
mask = (((result['g_auto'] - result['r_auto']) < (0.2 + 0.6 * (result['g_auto'] - result['i_auto']))) &
        ((result['g_auto'] - result['r_auto']) > (-0.2 + 0.6 * (result['g_auto'] - result['i_auto']))) &
        ((result['g_auto'] - result['i_auto']) > 0.5) & 
        ((result['g_auto'] - result['i_auto']) < 1.3) &
        ((result['i_auto']) < 24))

subset = result[mask]
subset = subset.sample(n=1000)

plt.figure()
plt.scatter(result['g_auto'] - result['i_auto'], result['g_auto'] - result['r_auto'], s=10, c='gray', edgecolor='none', alpha = 0.5)
plt.scatter(subset['g_auto'] - subset['i_auto'], subset['g_auto'] - subset['r_auto'], s=20, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['i_auto'], GCs['g_auto'] - GCs['r_auto'], s=10, c='red', edgecolor='none')
plt.xlabel('(g - i)')
plt.ylabel('(g - r)')
plt.xlim(-1,4)
plt.ylim(-1,4)

plt.figure()
plt.scatter(subset['g_auto'] - subset['r_auto'], subset['r_auto'], s=30, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['r_auto'], GCs['i_auto'], s=8, c='red', edgecolor='none')
plt.ylim(13,24)
plt.gca().invert_yaxis()
plt.xlabel('(g - i)')
plt.ylabel('i')

plt.figure()
plt.scatter(result['g_auto'] - result['u_auto'], result['g_auto'] - result['r_auto'], s=10, c='gray', edgecolor='none', alpha = 0.5)
plt.scatter(subset['g_auto'] - subset['u_auto'], subset['g_auto'] - subset['r_auto'], s=20, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['u_auto'], GCs['g_auto'] - GCs['r_auto'], s=10, c='red', edgecolor='none')
Example #41
0
allY = []
for file_name in args.files:
   Y = []
   with open(file_name) as fp:
      for idx, line in enumerate(fp):
         if len(Y) > args.size:
            break
         if args.type == 'epoch':
            if 'Epoch' not in line:
               continue
         else:
            if 'Episode' not in line:
               continue
         
         Y.append(float(line.split(' ')[-1][:-1]))
   allY.append(Y)

fig = plt.figure()
ax = plt.subplot(111)

plt.xlabel('epochs' if args.type == 'epoch' else 'episodes')
plt.ylabel('reward per epoch' if args.type == 'epoch' else 'reward per episode')
for idx, Y in enumerate(allY):
   ax.plot(Y, label=LABELS[idx])

plt.title('Instruction following learning performance one hot')
ax.legend(loc='upper center', shadow=True, ncol=2)
# plt.legend()
plt.show()
   
         
Example #42
0
index, dist2d, _ = cat1.match_to_catalog_sky(cat2)
mask = dist2d.arcsec < 0.3
new_idx = index[mask]

VIMOS = GCs.ix[mask].reset_index(drop=True)
BergondMatch = BergondGCs.ix[new_idx].reset_index(drop=True)
print len(BergondMatch)

x = VIMOS['VREL_helio']
xerr = VIMOS['VERR']
y = BergondMatch['HRV']
yerr = BergondMatch['e_HRV']

plt.errorbar(x,
             y,
             yerr=yerr,
             xerr=xerr,
             fmt='o',
             c='red',
             label='Bergond et al.')

plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.xlabel(r'Velocity from this work [km s$^-1$ ]')
plt.ylabel(r'Velocity from the literature [km s$^-1$ ]')
plt.legend(loc='upper left')
plt.tight_layout()
plt.show()

print 'rms (VIMOS - Bergond) GCs = ', np.std(x - y)
Example #43
0
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)
plt.axis('equal')
plt.show()
Example #44
0
    def show(self, w):
        """
        illustrate the learning curve

        Parameters
        ----------
        w : int, window size for smoothing the curve
        """
        if len(self.tn_mc) > 0:
            # malis training, increase number of subplots
            nsp = 5
        else:
            nsp = 3

        # print the maximum iteration
        self.print_max_update()

        # using K as iteration unit
        tn_it = self.tn_it
        for i in xrange(len(tn_it)):
            tn_it[i] = tn_it[i] / float(1000)
        tt_it = self.tt_it
        for i in xrange(len(tt_it)):
            tt_it[i] = tt_it[i] / float(1000)

        # plot data
        plt.subplot(1,nsp, 1)
        plt.plot(tn_it, self.tn_err, 'b.', alpha=0.2)
        plt.plot(tt_it, self.tt_err, 'r.', alpha=0.2)
        # plot smoothed line
        xne,yne = self._smooth( tn_it, self.tn_err, w )
        xte,yte = self._smooth( tt_it, self.tt_err, w )
        plt.plot(xne, yne, 'b')
        plt.plot(xte, yte, 'r')
        plt.xlabel('iteration (K)'), plt.ylabel('cost energy')

        plt.subplot(1,nsp,2)
        plt.plot(tn_it, self.tn_cls, 'b.', alpha=0.2)
        plt.plot(tt_it, self.tt_cls, 'r.', alpha=0.2)
        # plot smoothed line
        xnc, ync = self._smooth( tn_it, self.tn_cls, w )
        xtc, ytc = self._smooth( tt_it, self.tt_cls, w )
        plt.plot(xnc, ync, 'b', label='train')
        plt.plot(xtc, ytc, 'r', label='test')
        plt.xlabel('iteration (K)'), plt.ylabel( 'classification error' )

        if len(tn_it) == len( self.tn_re ):
            plt.subplot(1, nsp, 3)
            plt.plot(tn_it, self.tn_re, 'b.', alpha=0.2)
            plt.plot(tt_it, self.tt_re, 'r.', alpha=0.2)
            # plot smoothed line
            xnr, ynr = self._smooth( tn_it, self.tn_re, w )
            xtr, ytr = self._smooth( tt_it, self.tt_re, w )
            plt.plot(xnr, ynr, 'b', label='train')
            plt.plot(xtr, ytr, 'r', label='test')
            plt.xlabel('iteration (K)'), plt.ylabel( 'rand error' )


        if len(tn_it) == len( self.tn_mc ):
            plt.subplot(1, nsp, 4)
            plt.plot(tn_it, self.tn_mc, 'b.', alpha=0.2)
            plt.plot(tt_it, self.tt_mc, 'r.', alpha=0.2)
            # plot smoothed line
            xnm, ynm = self._smooth( tn_it, self.tn_mc, w )
            xtm, ytm = self._smooth( tt_it, self.tt_mc, w )
            plt.plot(xnm, ynm, 'b', label='train')
            plt.plot(xtm, ytm, 'r', label='test')
            plt.xlabel('iteration (K)'), plt.ylabel( 'malis weighted cost energy' )

        if len(tn_it) == len( self.tn_me ):
            plt.subplot(1, nsp, 5)
            plt.plot(tn_it, self.tn_me, 'b.', alpha=0.2)
            plt.plot(tt_it, self.tt_me, 'r.', alpha=0.2)
            # plot smoothed line
            xng, yng = self._smooth( tn_it, self.tn_me, w )
            xtg, ytg = self._smooth( tt_it, self.tt_me, w )
            plt.plot(xng, yng, 'b', label='train')
            plt.plot(xtg, ytg, 'r', label='test')
            plt.xlabel('iteration (K)'), plt.ylabel( 'malis weighted pixel error' )

        plt.legend()
        plt.show()
        return
Example #45
0
# create the integrator object
ta = hy.taylor_adaptive(
    # The ODEs.
    [(x, dxdt), (y, dydt), (z, dzdt), (px, dpxdt), (py, dpydt), (pz, dpzdt)],
    # The initial conditions.
    [-0.45, 0.80, 0.00, -0.80, -0.45, 0.58],
    # Operate below machine precision
    # and in high-accuracy mode.
    tol=1e-18,
    high_accuracy=True)

# integrate the RTBP up to time unit
t_grid = np.linspace(0, 200, 2500)
out = ta.propagate_grid(t_grid)
print(out)

# plot
from matplotlib.pylab import plt
plt.rcParams["figure.figsize"] = (12, 6)

plt.subplot(1, 2, 1)
plt.plot(out[4][:, 0], out[4][:, 1])
plt.xlabel("x")
plt.ylabel("y")
plt.subplot(1, 2, 2)
plt.plot(out[4][:, 0], out[4][:, 2])
plt.xlabel("x")
plt.ylabel("z")

plt.show()
Example #46
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()