Beispiel #1
0
def gen_bars(data, headers, datasets, methods):
    """
    Description:
    Inputs:
    Outputs:
    """
    width = 0.5
    x = np.arange(0, 16, 2)
    
    labels_x = datasets.copy()
    labels_x.insert(0,"") 
    
    fig, ax = plt.subplots()
    bar1 = ax.bar(x - (0.3 + width/2), data[0,:], width, label = methods[0])
    add_labels(ax, bar1)

    if (len(methods) > 1):
        bar2 = ax.bar(x , data[1,:], width, label = methods[1])
        add_labels(ax, bar2)
    
        if (len(methods) > 2):
            bar3 = ax.bar(x + (0.3 + width/2), data[1,:], width, label = methods[2])
            add_labels(ax, bar3)

    ax.set_ylabel(metric)
    ax.set_xlabel("Dataset")
    
    ax.set_xticklabels(labels_x)
    ax.set_title(metric + " Across Datasets")
    ax.legend(bbox_to_anchor=(1, 1.15), fancybox=True, framealpha=0.5)
 def allGraphs(self):
     colors = ['r', 'g', 'b', 'c', 'm', 'y', 'c']
     for f in range(len(self.features)):
         ax = plt.subplot(111)
         plt.xlabel('Standardized Feature Values')
         plt.ylabel('Probability')
         filename = self.resultsName + "_feature_" + str(
             self.features[f]) + "_std.png"
         title = "Histogram of feature: " + str(look.feat(self.features[f]))
         plt.title(title)
         plt.grid(True)
         for j in range(len(self.H_)):
             prob = self.H_[j][f][0]
             bins = self.H_[j][f][1]
             barBins = bins[0:-1]
             bw = barBins[1] - barBins[0]
             ax.bar(barBins,
                    prob,
                    width=bw,
                    facecolor=colors[j],
                    alpha=0.75,
                    label=look.classes(j))
         ax.legend(loc=0)
         plt.savefig(filename, bbox_inches='tight')
         plt.close()
Beispiel #3
0
def create_and_save_graph(df):
    # Filling NaN with 0
    df = df.fillna(0)
    # Selecting 11th row and 1st column
    df1_label = df.iloc[10:, :1]
    # Converting dataframe into list
    df1_label = df1_label.values.tolist()

    plt.gcf().subplots_adjust(bottom=0.15)
    trend_graph_path = os.path.join(os.path.dirname(__file__), 'shivam.png')
    # Select data for Grand Total Plot
    df1 = df.iloc[10:, 1:9]
    df1 = df1.iloc[0:, 1:]
    # Plot first graph
    ax = df1.T.plot(kind='line',
                    marker='s',
                    x_compat=True,
                    rot=0,
                    alpha=0.75,
                    grid=True)
    # Data for second graph
    df = df.iloc[:10, :9]
    df = df.drop(["Category"], axis=1)
    df_label = df.iloc[:, 0]
    df_label = df_label.values.tolist()
    df = df.iloc[0:, 1:]
    ax = df.T.plot(kind='bar',
                   width=0.9,
                   legend=False,
                   figsize=(60, 4),
                   ax=ax,
                   rot=0,
                   alpha=0.75,
                   grid=True,
                   colormap='Paired')

    x_offset = -0.02
    y_offset = 70.02

    for p in ax.patches:
        b = p.get_bbox()
        val = int(b.y1 + b.y0)
        ax.annotate(val, ((b.x0 + b.x1) / 2 + x_offset, b.y1 + y_offset),
                    rotation=90)

    patches, labels = ax.get_legend_handles_labels()
    labels = df1_label + df_label
    ax.legend(patches,
              labels,
              loc='upper center',
              bbox_to_anchor=(0.5, -0.05),
              ncol=11,
              fancybox=True,
              shadow=True,
              prop={'size': 10})

    plt.savefig(trend_graph_path, bbox_inches='tight', dpi=200)
def plot_graph(train_history, label_col, mode):

    # Obtain scores from history
    loss = train_history.history['loss'] #List
    val_loss = train_history.history['val_loss']

    #Check if binary or multiclass problem to obtain correct metrics
    if mode == 0:
        acc = train_history.history['binary_accuracy']
        val_acc = train_history.history['val_binary_accuracy']
    else:
        acc = train_history.history['categorical_accuracy']
        val_acc = train_history.history['val_categorical_accuracy']

    # Plot loss scores
    sns.set_style("whitegrid")
    fig, ax = plt.subplots(1, 1)
    ax.plot(loss, label = "Loss")
    ax.plot(val_loss, label = "Validation Loss")
    ax.set_title('Model Loss')
    ax.legend(loc = "upper right")
    ax.set_xlim([0, 100])
    ax.set_ylabel("Loss")
    ax.set_xlabel("Epochs")
    ax.minorticks_on()
    ax.grid(b=True, which='major')
    ax.grid(b=True, which='minor')
    plt.savefig(results_dir + '/' + label_col + '_loss.png')
    plt.show()

    # Plot accuracy scores
    fig, ax = plt.subplots(1, 1)
    ax.plot(acc, label = "Accuracy")
    ax.plot(val_acc, label = "Validation Accuracy")
    ax.set_title('Model Accuracy')
    ax.legend(loc = "lower right")
    ax.set_xlim([0, 100])
    ax.grid(b=True, which='major')
    ax.grid(b=True, which='minor')
    ax.set_ylabel("Accuracy")
    ax.set_xlabel("Epochs")
    ax.minorticks_on()
    plt.savefig(results_dir + '/' + label_col + '_acc.png')
    plt.show()
    return 0
Beispiel #5
0
    def draw(self, output_name, x, y_list):
        plt.autoscale(True, 'both', True)
        fig = plt.figure(figsize=(100, 10), dpi=300)
        lines = []
        ax = fig.add_subplot(111)

        for y in y_list:
            ys = y.split(',')
            l = None
            if len(ys) > 1:
                l = ys[1]
            y = ys[0].replace('.', '')
            line, = ax.plot(self.data[x], self.data[y], '-', label=l)
            lines.append(line)

        ax.set_xlabel(x)
        # handles, labels = ax.get_legend_handles_labels()
        ax.legend()
        plt.savefig(output_name, bbox_inches='tight')
        plt.clf()
Beispiel #6
0
	def draw(self, output_name, x, y_list):
		plt.autoscale(True, 'both', True)
		fig = plt.figure(figsize=(100,10), dpi=300)
		lines = []
		ax = fig.add_subplot(111)

		for y in y_list:
			ys = y.split(',')
			l = None
			if len(ys) > 1:
				l = ys[1]
			y = ys[0].replace('.','')
			line, = ax.plot(self.data[x], self.data[y], '-', label=l)
			lines.append(line)

		ax.set_xlabel(x)
		# handles, labels = ax.get_legend_handles_labels()
		ax.legend()
		plt.savefig(output_name, bbox_inches='tight')
		plt.clf()
 def printPost(self, prob):
     colors = ['r', 'g', 'b', 'c', 'm', 'y', 'x']
     ax = plt.subplot(111)
     plt.xlabel("Class")
     plt.ylabel("Relative Likelihood")
     plt.title("Posterior Probability")
     plt.tick_params(axis='x',
                     which='both',
                     bottom='off',
                     top='off',
                     labelbottom='off')
     width = 5
     for i, p in enumerate(prob):
         ax.bar(i * width,
                p * 100,
                width=width,
                facecolor=colors[i],
                alpha=0.75,
                label=look.classes(i))
     ax.legend(loc=0)
     plt.savefig(self.resultsName + "Img_" + str(self.currentImage) +
                 "_Prob.png",
                 bbox_inches='tight')
     plt.close()
Beispiel #8
0
    def draw(self, ax, output_mode):

        self.colorize_default_lines()
        for p in self.plots:
            p.draw(ax)
        if self.show_legend:
            leg = ax.legend(**self.legend_kwargs)
            if output_mode == "png":  #latex output doesn't support alpha
                leg.get_frame().set_alpha(0.5)
            plt.setp(leg.get_texts(), fontsize='small')

        ax.xaxis.set_label_text(self.x_axis_desc.label)
        ax.yaxis.set_label_text(self.y_axis_desc.label)
        ax.set_ybound(self.y_axis_desc.range_min, self.y_axis_desc.range_max)
        ax.set_xbound(self.x_axis_desc.range_min, self.x_axis_desc.range_max)

        ax.set_title(self.title)
Beispiel #9
0
	def draw(self,ax,output_mode):

		self.colorize_default_lines()
		for p in self.plots:
			p.draw(ax);
		if self.show_legend:
			leg=ax.legend(**self.legend_kwargs)
			if output_mode == "png": #latex output doesn't support alpha
				leg.get_frame().set_alpha(0.5);
			plt.setp(leg.get_texts(), fontsize='small')

		ax.xaxis.set_label_text(self.x_axis_desc.label)
		ax.yaxis.set_label_text(self.y_axis_desc.label)
		ax.set_ybound(self.y_axis_desc.range_min,self.y_axis_desc.range_max)
		ax.set_xbound(self.x_axis_desc.range_min,self.x_axis_desc.range_max)

		ax.set_title(self.title)
Beispiel #10
0
def optimization_run_property_per_multistart(
    results: Union[Result, Sequence[Result]],
    opt_run_property: str,
    axes: Optional[matplotlib.axes.Axes] = None,
    size: Tuple[float, float] = (18.5, 10.5),
    start_indices: Optional[Union[int, Iterable[int]]] = None,
    colors: Optional[Union[List[float], List[List[float]]]] = None,
    legends: Optional[Union[str, List[str]]] = None,
    plot_type: str = 'line',
) -> matplotlib.axes.Axes:
    """
    Plot stats for an optimization run property specified by opt_run_property.

    It is possible to plot a histogram or a line plot. In a line plot,
    on the x axis are the numbers of the multistarts, where the multistarts are
    ordered with respect to a function value. On the y axis of the line plot
    the value of the corresponding parameter for each multistart is displayed.

    Parameters
    ----------
    opt_run_property:
        optimization run property to plot.
        One of the 'time', 'n_fval', 'n_grad', 'n_hess', 'n_res', 'n_sres'
    results:
        Optimization result obtained by 'optimize.py' or list of those
    axes:
        Axes object to use
    size:
        Figure size (width, height) in inches. Is only applied when no ax
        object is specified
    start_indices:
        List of integers specifying the multistarts to be plotted or
        int specifying up to which start index should be plotted
    colors:
        List of RGBA colors (one color per result in results),
        or single RGBA color. If not set and one result, clustering is done
        and colors are assigned automatically
    legends:
        Labels for line plots, one label per result object
    plot_type:
        Specifies plot type. Possible values: 'line', 'hist', 'both'

    Returns
    -------
    ax:
        The plot axes.
    """
    supported_properties = {
        'time': 'Wall-clock time (seconds)',
        'n_fval': 'Number of function evaluations',
        'n_grad': 'Number of gradient evaluations',
        'n_hess': 'Number of Hessian evaluations',
        'n_res': 'Number of residuals evaluations',
        'n_sres': 'Number of residual sensitivity evaluations',
    }

    if opt_run_property not in supported_properties:
        raise ValueError("Wrong value of opt_run_property. Only the following "
                         "values are allowed: 'time', 'n_fval', 'n_grad', "
                         "'n_hess', 'n_res', 'n_sres'")

    # parse input
    (results, colors, legends) = process_result_list(results, colors, legends)

    # axes
    if axes is None:
        ncols = 2 if plot_type == 'both' else 1
        fig, axes = plt.subplots(1, ncols)
        fig.set_size_inches(*size)
        fig.suptitle(
            f'{supported_properties[opt_run_property]} per optimizer run')
    else:
        axes.set_title(
            f'{supported_properties[opt_run_property]} per optimizer run')

    # loop over results
    for j, result in enumerate(results):
        if plot_type == 'both':
            axes[0] = stats_lowlevel(
                result,
                opt_run_property,
                supported_properties[opt_run_property],
                axes[0],
                start_indices,
                colors[j],
                legends[j],
            )

            axes[1] = stats_lowlevel(
                result,
                opt_run_property,
                supported_properties[opt_run_property],
                axes[1],
                start_indices,
                colors[j],
                legends[j],
                plot_type='hist',
            )
        else:
            axes = stats_lowlevel(
                result,
                opt_run_property,
                supported_properties[opt_run_property],
                axes,
                start_indices,
                colors[j],
                legends[j],
                plot_type,
            )

    if sum((legend is not None for legend in legends)) > 0:
        if plot_type == 'both':
            for ax in axes:
                ax.legend()
        else:
            axes.legend()

    return axes
import matplotlib.pyplot as plt
import matplotlib.axes as ax
import pylab

# change to proper directory
os.chdir('C:\Users\Matt\Desktop\Python Projects\Exploratory Data Analysis')

# load file, select proper date range, convert row to numeric dtypes
hpc = pd.read_csv('household_power_consumption.txt', sep=';', index_col=['Date'], usecols=['Sub_metering_1', 'Sub_metering_2', 'Sub_metering_3', 'Date'])
# hpc = hpc.drop(['Date', 'Time'], axis=1).set_index('DT')
hpc = hpc['1/2/2007':'3/2/2007'].convert_objects(convert_numeric=True)
hpc = hpc[0:2881]
# create plotting variables
x = pd.date_range('2/1/2007', '2/3/2007 00:00', freq='T')
y1 = hpc.Sub_metering_1
y2 = hpc.Sub_metering_2
y3 = hpc.Sub_metering_3

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(x, y1, color='k', label='Sub_metering_1')
ax.plot(x, y2, color='r', label='Sub_metering_2')
ax.plot(x, y3, color='b', label='Sub_metering_3')
ax.legend(loc='best')
ax.set_xticklabels(['Thur', '', '', '', 'Fri', '', '', '','Sat'])
ax.set_yticklabels(['0', '',  '10', '', '20', '', '30'])

#plt.xlabel('Global Active Power (kilowatts)')
ax.set_ylabel('Energy sub metering')
#plt.title('Global Active Power')
pylab.show()
Beispiel #12
0
        assert mode
        assert solver
        data[(mode, solver)].append(sec)

l = list()
max_steps = max([len(v) for v in data.values()])
fig, ax = plt.subplots()
linestyles = ['-', '--', '-.', ':']
s = -1
for k, times in data.items():
    s = (s + 1) % len(linestyles)
    mode, solver = k
    if len(times) < max_steps:
        times += [timeout]*(max_steps - len(times))
    times = np.array(times)
    if log:
        times = np.log(times)
    plt.plot(times, label="{} {}".format(solver, mode), linewidth=3, linestyle=linestyles[s])

plt.grid("on")
plt.xlabel("Steps")
plt.ylabel("Cumulative Solve Time (s)")
plt.title("Solver Performance:" + args.configuration)

# borrowed from python tutorial
legend = ax.legend(loc='upper left', shadow=True, fontsize='large')
# Put a nicer background color on the legend.
legend.get_frame().set_facecolor('#00FFCC')

plt.show()
# change to proper directory
os.chdir('C:\Users\Matt\Desktop\Python Projects\Exploratory Data Analysis')

# load file, select proper date range, convert row to numeric dtypes
hpc = pd.read_csv(
    'household_power_consumption.txt',
    sep=';',
    index_col=['Date'],
    usecols=['Sub_metering_1', 'Sub_metering_2', 'Sub_metering_3', 'Date'])
# hpc = hpc.drop(['Date', 'Time'], axis=1).set_index('DT')
hpc = hpc['1/2/2007':'3/2/2007'].convert_objects(convert_numeric=True)
hpc = hpc[0:2881]
# create plotting variables
x = pd.date_range('2/1/2007', '2/3/2007 00:00', freq='T')
y1 = hpc.Sub_metering_1
y2 = hpc.Sub_metering_2
y3 = hpc.Sub_metering_3

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(x, y1, color='k', label='Sub_metering_1')
ax.plot(x, y2, color='r', label='Sub_metering_2')
ax.plot(x, y3, color='b', label='Sub_metering_3')
ax.legend(loc='best')
ax.set_xticklabels(['Thur', '', '', '', 'Fri', '', '', '', 'Sat'])
ax.set_yticklabels(['0', '', '10', '', '20', '', '30'])

#plt.xlabel('Global Active Power (kilowatts)')
ax.set_ylabel('Energy sub metering')
#plt.title('Global Active Power')
pylab.show()
Beispiel #14
0
for index, x in enumerate(tamañosC3):
    npArray = np.array(tamañosC3[x])
    #tamañosC0[x] = tamañosC0[x].mean()
    resC3.append(tamañosC3[x].mean())
    yTicks.append(tamañosC3[x].mean())



with PdfPages('ImagenFantasma_C_vs_ASM.pdf') as pdf:
    fig, ax= plt.subplots()
    ax.plot(tamaños, resASM, label="ASM", marker=".")
    ax.plot(tamaños, resC0, label="C0", marker=".")
    ax.plot(tamaños, resC2, label="C2", marker=".")
    ax.plot(tamaños, resC3, label="C3", marker=".")
    ax.legend(['ASM','O0','O2','O3'], loc='upper left')
    plt.xlabel("Cantidad de pixeles")
    plt.ylabel("Ciclos de clock")
    plt.title("Imagen Fantasma")
    #ax.set_xTicks = ['512','2048','8192','32768','120000','131072','480000','1920000']
    #ax.set_yTicks = [str(yTicks[i]) for i in range(0, len(yTicks))]
    ax.ticklabel_format(style='plain')
    ax.axis([0, 2000000, 0, 180000000])
    plt.grid( linestyle='-', linewidth=1)
    for tick in ax.get_xticklabels():
        tick.set_rotation(55)
    #plt.show()
    pdf.savefig(bbox_inches='tight')
    plt.close()

with PdfPages('ImagenFantasma_x_tamaño.pdf') as pdf:
# this number is taken from SVD on test_paramset_SVD_006
#ax.axvline(x=0.4248498, color='blue', linestyle='dashed', linewidth=2,
#        label='CLM with optimized params')
#ax.axvline(x=-0.18539695, color='blue', linestyle='dashed', linewidth=2,
#        label='CLM with optimized params')
# this number is taken from SVD on test_paramset_LHF_SVD_001
#ax.axvline(x=-0.36178064, color='lightblue', linestyle='dashed', linewidth=2,
#        label='CLM with optimized params V1')
# this number is taken from SVD on test_paramset_GPP_LHF_SVD_001
#ax.axvline(x=0.41596237, color='blue', linestyle='dashed', linewidth=2,
#        label='CLM with optimized params')
#ax.axvline(x=-0.27669725, color='blue', linestyle='dashed', linewidth=2,
#        label='CLM with optimized params')
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.6, box.height])
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
#plt.savefig("dist_outputdata_NNv005_GPP_SVD_md_mode1.pdf")
#plt.savefig("dist_outputdata_NNv006_GPP_SVD_md_mode1.pdf")
#plt.savefig("dist_outputdata_NNv001_LHF_SVD_md_mode1.pdf")
#plt.savefig("dist_outputdata_NNv002_LHF_SVD_md_mode1.pdf")
#plt.savefig("dist_outputdata_NNv001_GPP_LHF_SVD_md_mode1.pdf")
#plt.savefig("dist_outputdata_NNv001_GPP_SVD_md_mode1.pdf")
#plt.savefig("dist_outputdata_NNv001_GPP_LHFplot_SVD_md_mode1.pdf")
plt.show()

# Mode 2
fig = plt.figure()
ax = plt.subplot(111)
ax.hist(outputdata_GPP[:, 1], label='CLM PPE')
ax.hist(model_preds_GPP[:, 1], label='NN Preds')
plt.xlabel('EOF2 GPP')
Beispiel #16
0
    resC2.append(tamañosC2[x].mean())
    yTicks.append(tamañosC2[x].mean())

for index, x in enumerate(tamañosC3):
    npArray = np.array(tamañosC3[x])
    #tamañosC0[x] = tamañosC0[x].mean()
    resC3.append(tamañosC3[x].mean())
    yTicks.append(tamañosC3[x].mean())

with PdfPages('ImagenFantasma_C_vs_ASM.pdf') as pdf:
    fig, ax = plt.subplots()
    ax.plot(tamaños, resASM, label="ASM original", marker=".")
    ax.plot(tamaños, resC0, label="C0", marker=".")
    ax.plot(tamaños, resC2, label="ASM 2px", marker=".")
    ax.plot(tamaños, resC3, label="C3", marker=".")
    ax.legend(['ASM original', 'O0', 'ASM 2px', 'O3'], loc='upper left')
    plt.xlabel("Cantidad de pixeles")
    plt.ylabel("Ciclos de clock")
    plt.title("Imagen Fantasma")
    #ax.set_xTicks = ['512','2048','8192','32768','120000','131072','480000','1920000']
    #ax.set_yTicks = [str(yTicks[i]) for i in range(0, len(yTicks))]
    ax.ticklabel_format(style='plain')
    ax.axis([0, 2000000, 0, 180000000])
    plt.grid(linestyle='-', linewidth=1)
    for tick in ax.get_xticklabels():
        tick.set_rotation(55)
    #plt.show()
    pdf.savefig(bbox_inches='tight')
    plt.close()

with PdfPages('ImagenFantasma_C_vs_ASM_masAccesos.pdf') as pdf:
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(r_ECI[:, 0] / 1000,
        r_ECI[:, 1] / 1000,
        r_ECI[:, 2] / 1000,
        label='Orbital Position',
        color='k')

# Sphere to represent Earth
# Make data
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x1 = rEarth / 1000 * np.outer(np.cos(u), np.sin(v))
y1 = rEarth / 1000 * np.outer(np.sin(u), np.sin(v))
z1 = rEarth / 1000 * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax.plot_surface(x1, y1, z1, cmap='GnBu')

# Legend and labels
ax.legend()
ax.set_xlabel('X Pos (km)')
ax.set_ylabel('Y Pos (km)')
ax.set_zlabel('Z Pos (km)')
ax.set_aspect('equal')

plt.show()
imgh = np.reshape(img, nx*ny)
imgh1 = np.reshape(img_mask1, nx1*ny1)


df=36*38
dof=chi2_distance(imgh,imgh1)
chi2_distance(imgh, imght[0,:])
chi2_distance(imgh, imght[1,:])
chi2_distance(imgh, imght[2,:])
chi2_distance(imgh, imght[3,:])
chi2_distance(imgh, imght[4,:])
chi2_distance(imgh, imght[5,:])
chi2_distance(imgh, imght[6,:])

chi_sfh=np.array([502.5312995308081,580.45729191839803,204.19667370317001,518.27719309677684,1534.8645907539676,1555.9265125639893])


weights = np.ones_like(chi_sfh)/float(len(chi_sfh))
fig, ax = plt.subplots(1, 1)
mean, var, skew, kurt = chi2.stats(df, moments='mvsk')
x = np.linspace(chi2.ppf(0.01, df), chi2.ppf(0.99, df), 100)
xu = np.linspace(chi2.ppf(0.01, dof), chi2.ppf(0.99, dof), 100)
ax.axvline(x=dof/df,color='k', linestyle='dashed',lw=4, label='UGC11680NED01 $\chi^2$')
ax.hist(chi_sfh/df,bins=10, normed=False,weights=weights, histtype='step', lw=3,label='Mass $10<\log (M/M_{\odot})<11$ , color $2<g-r<3$')
ax.legend(loc='best', frameon=False)
ax.set_ylabel('Probability density $\chi ^2$')
ax.set_xlabel('$x$')
plt.show()