Beispiel #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()
Beispiel #2
0
def plot_four(plot_data):
    
    fig = plt.figure(figsize=(20, 10))
    
#    gs = gridspec.GridSpec(1, 2, height_ratios=[1, 2]) 
    
    ax = fig.add_subplot(223, projection='3d')
    ax.scatter(plot_data['sx'],  plot_data['sy'], plot_data['sz'])
    ax.plot(plot_data['sx'],  plot_data['sy'], plot_data['sz'], color='b')
    ax.view_init(azim=0, elev=90) #xy plane
    plt.xticks(fontsize=10)
    ax.set_title('Displacement Projection in xy Plane',size=20)

    ax2 = fig.add_subplot(224, projection='3d')
    ax2.scatter(plot_data['sx'],  plot_data['sy'], plot_data['sz'])
    ax2.plot(plot_data['sx'],  plot_data['sy'], plot_data['sz'], color='b')
    ax2.view_init(azim=0, elev=45) 
    ax2.set_title('Displacement',size=20)

    ax3 = fig.add_subplot(221)
    # 50 represents number of points to make between T.min and T.max
    xnew = np.linspace(0,8,50) 
    spl = make_interp_spline(pd.Series(range(9)), plot_data['tilt1'], k=3)  # type: BSpline
    x = spl(xnew)
    spl = make_interp_spline(pd.Series(range(9)), plot_data['tilt2'], k=3)  # type: BSpline
    y = spl(xnew)
    spl = make_interp_spline(pd.Series(range(9)), plot_data['compass'], k=3)  # type: BSpline
    z = spl(xnew)
    ax3.plot(x,"b-",label='tilt1')
    ax3.plot(y,"r-",label='tilt2')
    ax3.plot(z,"g-",label='compass')
    ax3.legend(loc="lower left",prop={'size': 20})
    ax3.set_title('Orientation Plot (degree)',size=20)
    ax3.tick_params(labelsize=20)
    
    ax4 = fig.add_subplot(222)
#    x = gaussian_filter1d(plot_data['ax'], sigma=1)    
#    y = gaussian_filter1d(plot_data['ay'], sigma=1)   
#    z = gaussian_filter1d(plot_data['az'], sigma=1)   
#    mag = gaussian_filter1d(plot_data['accelerometer'], sigma=1)   
    spl = make_interp_spline(pd.Series(range(9)), plot_data['ax'], k=3)  # type: BSpline
    x = spl(xnew)
    spl = make_interp_spline(pd.Series(range(9)), plot_data['ay'], k=3)  # type: BSpline
    y = spl(xnew)
    spl = make_interp_spline(pd.Series(range(9)), plot_data['az'], k=3)  # type: BSpline
    z = spl(xnew)
    spl = make_interp_spline(pd.Series(range(9)), plot_data['accelerometer'], k=3)  # type: BSpline
    mag = spl(xnew)
    ax4.plot(x/1000,"c--",label='ax')
    ax4.plot(y/1000,"g--",label='ay')
    ax4.plot(z/1000,"b--",label='az')
    ax4.plot(mag,"r-",label='Acc')

    ax4.legend(loc="lower left",prop={'size': 20})
    ax4.set_title('Acceleration Plot (g)',size=20)
    ax4.tick_params(labelsize=20)
    
    plt.tight_layout()
    plt.show()
    fig.savefig('FourInOne.png')
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(' ', ''))
Beispiel #4
0
def tmp(cm, acts):
    import matplotlib.pyplot as plt
    import numpy as np

    plt.imshow(cm, interpolation='nearest')
    plt.xticks(np.arange(0, len(acts)), acts)
    plt.yticks(np.arange(0, len(acts)), acts)
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 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_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(())
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)
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)
Beispiel #10
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')
Beispiel #11
0
def f3():
    xs = [0, 1, 2, 5]
    ys = [0, 0, 1, 1]
    fig, ax = plt.subplots()
    ax.set_yticklabels([])
    ax.set_xticklabels([])
    plt.plot(xs, ys, label="$f_n(x)$")

    plt.xticks(xs, ['', r'$n-1$', r'$n$', ''])
    plt.yticks([1], ['$1$'])

    plt.legend()
    ax.spines['left'].set_position('zero')
    ax.spines['right'].set_color('none')
    ax.spines['bottom'].set_position('zero')
    ax.spines['top'].set_color('none')
    ax.axis('equal')
    plt.show()
Beispiel #12
0
def f4():
    capped_xs = np.linspace(-0.94, 0.8, 1000)
    xs = np.linspace(-1, 1, 1000)
    ys = [1 / (1 - x) for x in capped_xs]

    def getN(N):
        def fN(x):
            total = 0.0
            for i in range(N + 1):
                total += x**i
            return total

        return fN

    yss = []
    for N in range(1, 4):
        fN = getN(N)
        yss.append([fN(x) for x in xs])
    fig, ax = plt.subplots()
    ax.set_yticklabels([])
    ax.set_xticklabels([])
    plt.plot(capped_xs, ys, label=r"$\frac{1}{1-x}$")

    for i, ys in enumerate(yss):
        plt.plot(xs, ys, label="$N={}$".format(i + 1), alpha=0.3)
    plt.plot([1, 1], [0, 5], "k--", alpha=0.3)
    plt.plot(-1,
             0.5,
             'o',
             markerfacecolor='None',
             markeredgecolor='C0',
             markersize=5)
    plt.xticks([-1, 1], ['-1', '1'])

    plt.legend()
    ax.spines['left'].set_position('zero')
    ax.spines['right'].set_color('none')
    ax.spines['bottom'].set_position('zero')
    ax.spines['top'].set_color('none')
    ax.axis('equal')
    plt.show()
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)
Beispiel #14
0
def tmp2(cm, acts):
    import numpy as np
    import matplotlib.pyplot as plt

    conf_arr = cm

    norm_conf = []
    for i in conf_arr:
        a = 0
        tmp_arr = []
        a = sum(i, 0)
        for j in i:
            tmp_arr.append(0 if a == 0 else float(j) / float(a))
        norm_conf.append(tmp_arr)

    fig = plt.figure(figsize=(8, 8))
    plt.clf()
    ax = fig.add_subplot(111)
    ax.set_aspect(1)
    res = ax.imshow(np.array(norm_conf),
                    cmap=plt.cm.jet,
                    interpolation='nearest')

    width, height = conf_arr.shape

    # for x in range(width):
    # 	for y in range(height):
    # 		ax.annotate(str(conf_arr[x][y]), xy=(y, x),
    # 					horizontalalignment='center',
    # 					verticalalignment='center')

    cb = fig.colorbar(res)
    ax.set_xlim(-.5, len(acts) - .5)
    ax.set_ylim(-.5, len(acts) - .5)

    # alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    plt.xticks(range(width), acts, rotation=-90)
    plt.yticks(range(height), acts)
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()
Beispiel #16
0
import os
import numpy as np
from joblib import load
from matplotlib.pylab import plt

dataset = 'BANC_freesurf'
tpot_dict = 'gpr'
project_wd = os.getcwd()
saved_tpot = load(
    os.path.join(project_wd, 'tpot_%s_%s.dump' % (dataset, tpot_dict)))

# Get the internal cross validation scores
cv_scores = [
    saved_tpot['evaluated_individuals_'][model]['internal_cv_score']
    for model in saved_tpot['evaluated_individuals_'].keys()
]
model_names = [model for model in saved_tpot['evaluated_individuals_'].keys()]
# Just a quick solution to plot something, but you should plot histograms
ind = np.arange(len(cv_scores))
plt.bar(ind, cv_scores)
plt.ylabel('MAE')
plt.xticks(ind)
plt.show()

plt.figure()
plt.scatter(cv_scores)
plt.show()
Beispiel #17
0
# In[100]:

get_ipython().run_cell_magic(
    'latex', '',
    '$\\textbf{Visualize the Correlations}: $\n$\\text{Cor}(X_i,Y_j) = \\frac{\\text{Cov}(X_i,Y_j)}{\\sigma_{X_i}\\sigma_{Y_j}}$'
)

# In[101]:

R = np.corrcoef(data.T)
plt.figure(figsize=(10, 8))
plt.pcolor(R)
plt.colorbar()
plt.xlim([0, len(headers)])
plt.ylim([0, len(headers)])
plt.xticks(np.arange(32) + 0.5, np.array(headers), rotation='vertical')
plt.yticks(np.arange(32) + 0.5, np.array(headers))
plt.show()

# In[108]:

#Lets fit both the models using PCA/FA down to two dimensions.

#construct a function implementing the factor analysis which returns a vector of n_components largest
# variances and the corresponding components (as column vectors in a matrix). You can
# check your work by using decomposition.FactorAnalysis from sklearn


#### ~THIS FUNCTION IS WAS A STAB, NEW CODE HERE: ###########
def FactorAnalysis(data, n_components):
    ni = 20
Beispiel #18
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)

cumulative_months = []
months_label = []
for m in range(1, 13):
    if m < 10:
        pad = '0' + str(m)
    else:
        pad = str(m)
    year_month = "2017-" + pad
    month_data = df[df["month"] == year_month]
    month_data.drop(columns=["month", "well"], inplace=True)
    cumulative_month = sum(month_data.values.flatten())

    cumulative_months.append(cumulative_month)
    months_label.append("m-" + str(m))

month_count = 12
y_pos = np.arange(month_count)

plt.bar(y_pos, cumulative_months, align='center', alpha=0.5)
plt.xticks(y_pos, months_label)
plt.ylabel('Pumped water')
plt.title('Well water pumped in one year 2017')

plt.show()
Beispiel #19
0
import pandas as pd
import numpy as np
from matplotlib.pylab import plt  #load plot library

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

cum_pump = []
wells_label = []
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()
    effective = data[0:len(data) - 1]
    my_cumulative_pump = sum(effective)
    cum_pump.append(my_cumulative_pump)
    print("well:", well_i, "; pump:", my_cumulative_pump)

    wells_label.append('W-' + str(well_i))

well_count = 17
y_pos = np.arange(well_count)

plt.bar(y_pos, cum_pump, align='center', alpha=0.5)
plt.xticks(y_pos, wells_label)
plt.ylabel('Pumped water')
plt.title('Well water pumped in one year 2017')

print("Total water usage:", sum(cum_pump))
plt.show()
def multiplot_gen_content_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 =[]
    y7 =[]
    y8 =[]
    y9 =[]
    y10 =[]
    y11 =[]
    y12 =[]
    y13 =[]
    y14 =[]
    y15 =[]
    
    print("---",y1)
    
    for year in data.keys():
        for option_name, count in data[year].items():
            if option_name == 'script':
                y1.append(count)
            if option_name == 'xmlhttprequest':
                y2.append(count)
            if option_name == 'document':
                y3.append(count)
            if option_name == 'elemhide':
                y4.append(count)
            if option_name == 'subdocument':
                y5.append(count)
            if option_name == 'image':
                y6.append(count)
            if option_name == 'popup':
                y7.append(count)
            if option_name == 'ping':
                y8.append(count)
            if option_name == 'stylesheet':
                y9.append(count)
            if option_name == 'object':
                y10.append(count)
            if option_name == 'generichide':
                y11.append(count)
            if option_name == 'font':
                y12.append(count)
            if option_name == 'media':
                y13.append(count)
            if option_name == 'genericblock':
                y14.append(count)
            if option_name == 'other':
                y15.append(count)
    
    print("x-->",x)
    print("y-->",y1)
    print("y-->",y2)

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

    
    plt.legend(ncol=2)

    plt.tight_layout()
    plt.savefig('easylist-content-type.pdf ', format='pdf', dpi=1200)