Beispiel #1
0
    def _save(self, name='wiki1'):
        '''

        Parameters
        ----------
        name : TYPE, optional
            DESCRIPTION. The default is 'wiki1'.

        Returns
        -------
        None.

        '''
        fraction = 1
        width = 212
        fig, ax = plt.subplots(figsize=set_size(width, fraction),
                               sharex='all',
                               gridspec_kw={'hspace': 0.5})
        #plt.plot(self.y10, color='green', alpha=0.9)
        plt.plot(self.y50, color='red', alpha=0.8, label='OFAT')
        plt.plot(self.y_test, color='olive', alpha=0.8, label='ground truth')
        ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        ax.xaxis.set_major_locator(plt.LinearLocator(6))
        ax.yaxis.set_major_locator(plt.LinearLocator(6))
        plt.legend(loc='upper right', bbox_to_anchor=(1.0, 1.05), ncol=2)
        plt.xlabel('Time (days)')
        #print('{} smae: {} std: {}'.format(name, self.smae, self.std_s))
        plt.ylabel('Weekly prices')
        plt.tight_layout()
        plt.savefig('../../ofat/figures/' + name + '.pdf',
                    format='pdf',
                    bbox_inches='tight')
Beispiel #2
0
def fluxCor(s2d, arm, fluxf, countf):
    print '\tConverting counts to flux'
    fluxspec = np.array(pyfits.getdata(fluxf, 0)[0].transpose())
    countspec = np.array(pyfits.getdata(countf, 0)[0].transpose())
    wlkey, wlstart = 'NAXIS%i' % s2d.dAxis[arm], 'CRVAL%i' % s2d.dAxis[arm]
    wlinc, wlpixst = 'CDELT%i' % s2d.dAxis[arm], 'CRPIX%i' % s2d.dAxis[arm]
    head = pyfits.getheader(fluxf, 0)
    pix = np.arange(head[wlkey]) + 1
    wave = (head[wlstart] + (pix - head[wlpixst]) * head[wlinc]) * s2d.wlmult
    count = np.where(countspec == 0, 1E-5, countspec)
    resp = fluxspec / count
    tck = interpolate.InterpolatedUnivariateSpline(wave, resp)
    respm = tck(s2d.wave[arm])
    fig = plt.figure(figsize=(9, 9))
    ax = fig.add_subplot(1, 1, 1)
    ax.yaxis.set_major_formatter(plt.FormatStrFormatter(r'$%s$'))
    ax.xaxis.set_major_formatter(plt.FormatStrFormatter(r'$%i$'))

    ax.set_yscale('log', subsx=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    ax.plot(s2d.wave[arm], respm, 'o')
    ax.set_xlabel(r'$\rm{Observed\,wavelength\,(\AA)}$')
    ax.set_ylabel(r'$\rm{Response\,function}$')
    fig.savefig('%s_resp_%s.pdf' % (s2d.object, arm))
    s2d.data[arm] = (respm * s2d.data[arm].transpose()).transpose()
    s2d.erro[arm] = (respm * s2d.erro[arm].transpose()).transpose()
Beispiel #3
0
def setticks(ax,
             xlog=False,
             ylog=False,
             xmajor=5,
             xminor=1,
             ymajor=2,
             yminor=0.5):

    if not xlog:
        xmajorLocator = pylab.MultipleLocator(xmajor)
        xmajorFormatter = pylab.FormatStrFormatter('%d')
        xminorLocator = pylab.MultipleLocator(xminor)
        ax.xaxis.set_major_locator(xmajorLocator)
        #ax.xaxis.set_major_formatter(xmajorFormatter)
        ax.xaxis.set_minor_locator(xminorLocator)

    if not ylog:
        ymajorLocator = pylab.MultipleLocator(ymajor)
        ymajorFormatter = pylab.FormatStrFormatter('%d')
        yminorLocator = pylab.MultipleLocator(yminor)
        ax.yaxis.set_major_locator(ymajorLocator)
        #ax.yaxis.set_major_formatter(ymajorFormatter)
        ax.yaxis.set_minor_locator(yminorLocator)

    ax.get_yaxis().set_tick_params(which='both', direction='out')
    ax.get_xaxis().set_tick_params(which='both', direction='out')
    for tick in ax.xaxis.get_ticklines():
        tick.set_markersize(4.5)
    for tick in ax.yaxis.get_ticklines():
        tick.set_markersize(4.5)
    for tick in ax.xaxis.get_ticklines(minor=True):
        tick.set_markersize(2.5)
    for tick in ax.yaxis.get_ticklines(minor=True):
        tick.set_markersize(2.5)
Beispiel #4
0
    def plotAllShots(self, C_Selector=0):

        idx = self.cluster_list[C_Selector]
        Deltas = self.delta_shot
        Psis = self.psi_shot
        WL = self.WLarray

        fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))
        fig.tight_layout(pad=4)

        ax1.clear
        ax1.scatter(self.WLarray, Deltas[C_Selector], color='red')
        ax1.set_title('Delta', fontsize='xx-large')
        ax1.set_xticklabels(self.WLarray, fontsize='xx-large')
        ax1.set_yticklabels(Deltas[C_Selector], fontsize='xx-large')
        ax1.set_xlabel('Wavelength (nm)', fontsize='xx-large')
        ax1.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        fig.suptitle('Cluster index: {}'.format(C_Selector),
                     y=1.05,
                     fontsize='xx-large')
        ax2.clear
        ax2.scatter(self.WLarray, Psis[C_Selector], color='blue')
        ax2.set_title('Psi', fontsize='xx-large')
        ax2.set_xticklabels(self.WLarray, fontsize='xx-large')
        ax2.set_yticklabels(Psis[C_Selector], fontsize='xx-large')
        ax2.set_xlabel('Wavelength (nm)', fontsize='xx-large')
        ax2.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        ax2.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        for C_Selector in self.cluster_list:
            ax1.plot(self.WLarray, Deltas[C_Selector], alpha=0.7)
            ax2.plot(self.WLarray, Psis[C_Selector], alpha=0.7)

        return fig
Beispiel #5
0
def main():

    df = pd.read_csv('./log_files/2020-05-10-09:19:25_HAC_log.csv')
    print(df.cumulated_reward)
    fig, ax = plt.subplots()
    ax.plot(np.arange(len(df.cumulated_reward)), df.cumulated_reward)
    #ax.xaxis.set_major_locator(plt.MultipleLocator(20))
    #ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%d'))
    ax.yaxis.set_major_locator(plt.MultipleLocator(20))
    ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%d'))
    # For the minor ticks, use no labels; default NullFormatter.
    #ax.xaxis.set_minor_locator(plt.MultipleLocator(5))
    plt.show()

    df = pd.read_csv('./log_files/2020-05-10-09:19:25_other_HAC_log.csv')
    print(df.cumulated_reward)
    fig, ax = plt.subplots()
    ax.plot(np.cumsum(df.steps), df.cumulated_reward)
    # ax.xaxis.set_major_locator(plt.MultipleLocator(20))
    # ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%d'))
    ax.yaxis.set_major_locator(plt.MultipleLocator(20))
    ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%d'))
    # For the minor ticks, use no labels; default NullFormatter.
    # ax.xaxis.set_minor_locator(plt.MultipleLocator(5))
    plt.show()


    '''plt.plot(np.cumsum(r.monitor.l), pu.smooth(r.monitor.r, radius=10))
Beispiel #6
0
 def set_appearance(self):
     # ----------------------------------------------------
     figsize_hor = 3.14  # Length[inch]
     figsize_ver = 2.355  # Width[inch]
     x_min = 0.0
     x_max = 2.0001
     y_min = -2.0
     y_max = 2.0001
     x_step = 0.5
     y_step = 0.5
     # ----------------------------------------------------
     plt.figure(self.number, figsize=(figsize_hor, figsize_ver))
     plt.rcParams['font.family'] = 'Times New Roman'
     plt.rcParams['mathtext.fontset'] = 'stix'
     plt.rcParams['font.size'] = 8
     plt.rcParams['xtick.direction'] = 'in'
     plt.rcParams['ytick.direction'] = 'in'
     plt.rcParams['axes.linewidth'] = 0.5
     plt.rcParams['axes.grid'] = True
     plt.rcParams['grid.linestyle'] = '--'
     plt.rcParams['grid.linewidth'] = 0.3
     plt.rcParams["legend.edgecolor"] = 'black'
     plt.rcParams["legend.fancybox"] = False
     plt.xlabel(r"$x$")
     plt.ylabel(r"$y$")
     plt.axis([x_min, x_max, y_min, y_max])
     plt.xticks(np.arange(x_min, x_max, x_step))
     plt.yticks(np.arange(y_min, y_max, y_step))
     plt.tick_params(width=0.5)
     plt.gca().xaxis.set_major_formatter(
         plt.FormatStrFormatter('%.1f'))  # Display format of x axis
     plt.gca().yaxis.set_major_formatter(
         plt.FormatStrFormatter('%.1f'))  # Display format of y axis
     return
Beispiel #7
0
 def plot(self, name='wikipgs'):
     fraction = 1
     width = 512
     fig, ax = plt.subplots(figsize=set_size(width, fraction),
                            sharex='all',
                            gridspec_kw={'hspace': 0.5})
     #plt.plot(self.uncertainty, color='green', alpha=0.9)
     #plt.plot(self.y50,alpha=0.8, label='ofat')
     plt.plot(self.y_test, alpha=0.8, label='gt')
     plt.plot(self.yqcnn, alpha=0.8, label='qcnn')
     plt.plot(self.ycnn, alpha=0.8, label='cnn')
     plt.plot(self.yqclnn, alpha=0.8, label='qconvl')
     plt.plot(self.yqlstm[1], alpha=0.8, label='qlstm')
     plt.plot(self.ylstm, alpha=0.6, label='lstm')
     ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
     ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
     ax.xaxis.set_major_locator(plt.LinearLocator(6))
     ax.yaxis.set_major_locator(plt.LinearLocator(6))
     plt.legend(loc='upper right',
                bbox_to_anchor=(1.01, 1.05),
                ncol=3,
                columnspacing=0.5)
     plt.xlabel('Time (days)')
     #print('{} smae: {} std: {}'.format(name, self.smae, self.std_s))
     plt.ylabel('Daily page visits')
     plt.tight_layout()
Beispiel #8
0
    def plotClusterRawValues(self, C_Selector=0, idxSelector=0):

        C_ys, C_xs = self.cluster_coordinates[C_Selector]
        Dmap = self.AllShuffledStack[C_ys, C_xs,
                                     self.DeltaIndices[idxSelector]]
        Pmap = self.AllShuffledStack[C_ys, C_xs, self.PsiIndices[idxSelector]]
        bins = int(len(Dmap) / 10)

        fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))
        fig.tight_layout(pad=4)

        ax1.clear
        ax1.hist(Dmap, bins=bins, color='red')
        ax1.set_title(
            'Not segmented Delta values on cluster {}'.format(C_Selector),
            fontsize='xx-large')
        ax1.set_xticklabels(Dmap, fontsize='xx-large')
        ax1.xaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax1.set_yticklabels(np.histogram(Dmap)[0], fontsize='xx-large')
        ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        fig.suptitle('Map index: {} -- Wavelength: {} nm'.format(
            idxSelector, self.WLdict[idxSelector]),
                     y=1.05,
                     fontsize='xx-large')
        ax2.clear
        ax2.hist(Pmap, bins=bins, color='blue')
        ax2.set_title(
            'Not segmented Psi values on cluster {}'.format(C_Selector),
            fontsize='xx-large')
        ax2.set_xticklabels(Pmap, fontsize='xx-large')
        ax2.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        ax2.set_yticklabels(np.histogram(Pmap)[0], fontsize='xx-large')
        ax2.yaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))

        return fig
Beispiel #9
0
def plot_figs(fig_num, elev, azim, a):
    fig = plt.figure(fig_num, figsize=(4, 3))
    plt.clf()
    ax = Axes3D(fig, elev=elev, azim=azim)

    ax.scatter(body_mass, work_level, heat_output, c='k', marker='+')
   
    X = np.arange(55, 85, 0.5)
    Y = np.arange(90, 180, 0.5)
    X, Y = np.meshgrid(X, Y)
    Z = a[0] + a[1]*X + +(Y/(a[2]+a[3]*X))
    ax.plot_surface(X, Y, Z,alpha=.5, antialiased=True,rstride=200, cstride=100, cmap=plt.cm.coolwarm)
             
    ax.set_xlabel('BODY_MASS', color='b')
    ax.set_ylabel('WORK_LEVEL', color='b')
    ax.set_zlabel('HEAT_OUTPUT', color='b')
    
    ax.w_xaxis.set_ticklabels([])
    ax.w_yaxis.set_ticklabels([])
    ax.w_zaxis.set_ticklabels([])
    
    ax.zaxis.set_major_locator(plt.LinearLocator(10))  
    ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.f'))
    ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.f'))
    ax.zaxis.set_major_formatter(plt.FormatStrFormatter('%.f'))
Beispiel #10
0
    def plotBarSegmentedMap(self, C_Selector=0, idxSelector=0):
        Dmap = self.segmentedShuffledStack[:, :,
                                           self.DeltaIndices[idxSelector]]
        Pmap = self.segmentedShuffledStack[:, :, self.PsiIndices[idxSelector]]

        D_Cvalues, D_Ccounts = np.unique(Dmap, return_counts=True)
        P_Cvalues, P_Ccounts = np.unique(Pmap, return_counts=True)

        D_varwidth = (D_Cvalues.max() - D_Cvalues.min()) / 20
        P_varwidth = (P_Cvalues.max() - P_Cvalues.min()) / 20
        SelectedDval = self.delta_shot[C_Selector][self.WLIndices[idxSelector]]
        SelectedPVal = self.psi_shot[C_Selector][self.WLIndices[idxSelector]]

        fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))
        fig.tight_layout(pad=4)

        ax1.clear
        ax1.bar(D_Cvalues,
                D_Ccounts,
                edgecolor='green',
                linewidth=2.5,
                width=D_varwidth,
                color='red')
        ax1.axvline(x=SelectedDval,
                    color='black',
                    label='cluster {} at {}'.format(C_Selector, SelectedDval))
        ax1.legend(fontsize='xx-large')
        ax1.set_title('Delta clusters values and their pixel counts',
                      fontsize='xx-large')
        ax1.set_xticklabels(D_Cvalues, fontsize='xx-large')
        ax1.xaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax1.set_yticklabels(D_Ccounts, fontsize='xx-large')
        ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
        fig.suptitle('Map index: {} -- Wavelength: {} nm'.format(
            idxSelector, self.WLdict[idxSelector]),
                     y=1.05,
                     fontsize='xx-large')
        ax2.clear
        ax2.bar(P_Cvalues,
                P_Ccounts,
                edgecolor='green',
                linewidth=2.5,
                width=P_varwidth,
                color='blue')
        ax2.axvline(x=SelectedPVal,
                    color='black',
                    label='cluster {} at {}'.format(C_Selector, SelectedPVal))
        ax2.legend(fontsize='xx-large')
        ax2.set_title('Psi clusters values and their pixel counts',
                      fontsize='xx-large')
        ax2.set_xticklabels(P_Cvalues, fontsize='xx-large')
        ax2.xaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
        ax2.set_yticklabels(P_Ccounts, fontsize='xx-large')
        ax2.yaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))

        return fig
def plot(actual_data,
         predicted_data,
         end_of_training_point,
         x_axis,
         title='',
         errors=None):
    fig, axs = plt.subplots(2, sharex=False, sharey=False)

    actual_prices_plot = axs[0].plot_date(x_axis, actual_data, 'b*-')
    predicted_prices_plot = axs[0].plot_date(x_axis,
                                             predicted_data,
                                             'r*--',
                                             label='predicted_prices')

    axs[0].set_ylabel("Adjusted Closing Price")
    axs[0].yaxis.set_major_formatter(plt.FormatStrFormatter('$%.2f'))
    axs[0].axvline(x=end_of_training_point, color='orange')

    errors_as_percentage = \
        ((numpy.asarray(actual_data) - numpy.asarray(predicted_data)) / numpy.asarray(actual_data)) * 100
    positive_values, negative_values = errors_as_percentage >= 0, errors_as_percentage < 0
    axs[1].bar(numpy.asarray(x_axis)[positive_values],
               errors_as_percentage[positive_values],
               color='g')
    axs[1].bar(numpy.asarray(x_axis)[negative_values],
               errors_as_percentage[negative_values],
               color='r')
    axs[1].axvline(x=end_of_training_point, color='orange')
    axs[1].yaxis.set_major_formatter(plt.FormatStrFormatter('%3.3f%%'))

    axs[1].set_ylabel("difference as percentage")
    axs[0].set_xlabel("Trading Day")

    fig.autofmt_xdate()
    plt.title(title)
    ####################################################################################

    fig, ax = plt.subplots(1)
    actual_prices_plot = plt.plot(x_axis, actual_data, 'b*-')
    predicted_prices_plot = plt.plot(x_axis,
                                     predicted_data,
                                     'r*--',
                                     label='predicted_prices')
    plt.axvline(x=end_of_training_point, color='orange')
    fig.autofmt_xdate()

    if errors:
        plt.figure()
        _ = plt.plot(xrange(len(errors)), errors, 'r--')
        plt.xlabel('Epoch')
        plt.ylabel('Relative Error')
        plt.title('Neural Network Relative Error History')

    plt.ioff()
    plt.show()
Beispiel #12
0
def plot_peak_hold(axis,
                   stft_data,
                   frequency_array,
                   title=False,
                   xlabel=False,
                   ylabel=False,
                   plot_freq_limits=False,
                   plot_amp_limits=False,
                   limit_array=False,
                   trace_label=False):
    """Plot the peak hold for a 2D STFT array

    Args:
        axis: matplotlip axis that this plot should be added to
        stft_data: A 2D numpy ndarray of shape (time, freq) containing the
            amplitude over both freq and time.
        frequency_array: A 1D numpy ndarray containing hte frequencies in
            Hz of the stft_data.
        title: An optional title to be added to the plot
        xlabel: An optional x-axis label to be added to the plot
        ylabel: An optional y-axis label to be added to the plot
        plot_freq_limits: An optional tuple containing the starting and ending
            frequencies to be used in the plot
        limit_array: An optional 1D numpy ndarray containing the limits for the
            plotted data of dtype = [('frequency', 'f8'), ('amplitude', 'f8')]

    Returns:
        matplolib handle to the axis

    Raises:
    """
    peak_hold = calculate_peak_hold(stft_data, frequency_array)
    if trace_label is not False:
        axis.loglog(peak_hold['frequency'],
                    peak_hold['amplitude'],
                    label=trace_label)
    else:
        axis.loglog(peak_hold['frequency'], peak_hold['amplitude'])
    if limit_array is not False:
        axis.loglog(limit_array['frequency'], limit_array['amplitude'])
    if plot_freq_limits is not False:
        axis.set_xlim(plot_freq_limits)
    if plot_amp_limits is not False:
        axis.set_ylim(plot_amp_limits)
    if title is not False:
        axis.set_title(title)
    if xlabel is not False:
        axis.set_xlabel(xlabel)
    if ylabel is not False:
        axis.set_ylabel(ylabel)
    axis.xaxis.set_major_formatter(plt.FormatStrFormatter('%g'))
    axis.yaxis.set_major_formatter(plt.FormatStrFormatter('%g'))
    axis.grid(b=True, which='major', color='0.25', linestyle='-')
    axis.grid(b=True, which='minor', color='0.75', linestyle='-')
    axis.set_axisbelow(True)
Beispiel #13
0
def weisskoff_figure(fluctuations,
                     theoretical_fluctuations,
                     rdc,
                     max_fluctuation,
                     max_roi_size,
                     title=None):
    """ Return a matplotlib figure containing the Weisskoff analysis.

    Parameters
    ----------
    fluctuation: 2-uplet
        the roi sizes array and the fluctuation array.
    theoretical_fluctuation: 2-uplet
        the roi sizes array and the theoretical fluctuation array.
    """
    figure = plt.figure()
    plot = figure.add_subplot(111)
    plot.grid(True, which="both", ls="-")
    plot.axes.loglog()

    if title:
        plt.title("{0}\nWeisskoff analysis".format(title))
    else:
        plt.title("Weisskoff analysis")
    plot.plot(fluctuations[0, :],
              100 * fluctuations[1, :],
              "ko-",
              fillstyle="full")
    plot.plot(theoretical_fluctuations[0, :],
              100 * theoretical_fluctuations[1, :],
              "ko-",
              markerfacecolor="w")

    ymin, ymax = plt.ylim()
    plot.plot([rdc, rdc], [ymin, 100 * max_fluctuation], "r-")
    plot.plot([rdc, max_roi_size],
              [100 * max_fluctuation, 100 * max_fluctuation], "r-")
    plt.ylim((ymin, ymax))
    plt.xlim((1, max_roi_size + 10))

    plot.text(rdc,
              ymin,
              'rdc = {0}'.format(round(rdc, 2)),
              verticalalignment='bottom',
              horizontalalignment='right',
              color='red',
              fontsize=10)
    #    plt.xticks(list(plt.xticks()[0]) + [rdc])
    plot.axes.set_xlabel("ROI width (pixels)")
    plot.axes.set_ylabel("Fluctuation (%)")
    plot.xaxis.set_major_formatter(plt.FormatStrFormatter("%.2f"))
    plot.yaxis.set_major_formatter(plt.FormatStrFormatter("%.2f"))
    plot.legend(("Measured", "Theoretical"), "upper right")
    return figure
Beispiel #14
0
def graph_format(ax):
    ax.set_xlim(graph.MinPeriod, graph.MaxPeriod)
    ax.set_ylim(graph.MinVel, graph.MaxVel)
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.grid(which="both")
    ax.legend()
    ax.get_xaxis().set_major_formatter(plt.FormatStrFormatter('%.2f'))
    ax.get_yaxis().set_major_formatter(plt.FormatStrFormatter('%.0f'))
    ax.set_xlabel(graph.XLabel)
    ax.set_ylabel(graph.YLabel)
def plot_bounds(sn_bounds):
    production_years = sorted(sn_bounds.keys())
    plt.figure(num=f"Ihagee serial numbers - bounds",
               figsize=(10, 6),
               tight_layout=True)
    for yr in production_years:
        plt.plot((yr, yr), sn_bounds[yr], "k.-")
    plt.xlabel("Production year")
    plt.ylabel("Serial number")
    axes = plt.gca()
    axes.xaxis.set_major_formatter(plt.FormatStrFormatter("%d"))
    axes.yaxis.set_major_formatter(plt.FormatStrFormatter("%d"))
def plot_intervals(models_data):
    plt.figure(num=f"Ihagee serial numbers - intervals",
               figsize=(10, 6),
               tight_layout=True)
    for start, end, model, type_id, size, low, high in models_data:
        if len(start) > 0 and len(end) > 0 and len(low) > 0 and len(high) > 0:
            plt.plot((int(start), int(end)), (int(low), int(high)), "k.-")
    plt.xlabel("Production year")
    plt.ylabel("Serial number")
    axes = plt.gca()
    axes.xaxis.set_major_formatter(plt.FormatStrFormatter("%d"))
    axes.yaxis.set_major_formatter(plt.FormatStrFormatter("%d"))
Beispiel #17
0
def id_spec(spec, model):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.fmt_xdata = plt.FormatStrFormatter('%4.2f')
    ax.fmt_ydata = plt.FormatStrFormatter('%4.2f')
    from scipy import ndimage, interpolate

    skymodel = model['model']
    data = spec.copy()
    blue, red, scale = model['blue'], model['red'], model['scale']
    while (red - blue) / scale < data.size:
        red += scale
        blue -= scale
    wave = scipy.arange(blue, red, scale)
    blue, red = model['blue'], model['red']
    sky = interpolate.splev(wave, skymodel)

    sky /= sky.mean() / data.mean()
    plt.plot(wave, sky, c='gray')

    from scipy import optimize, signal
    corr = signal.correlate(sky, data, mode='valid')
    w0 = wave[corr.argmax()]
    p = [w0, scale, 0., 0., 1.]
    xvals = numpy.arange(data.size).astype(numpy.float32)

    def opt(p):
        p = numpy.array(p)
        n = p[-1]
        coeff = numpy.atleast_2d(p[:-1]).T
        m = {'coeff': coeff, 'type': 'polynomial'}
        w = sf.genfunc(xvals, 0., m)
        mod = n * interpolate.splev(w, skymodel)
        return (data - mod) / abs(data)**0.5

    #coeff,ier = optimize.leastsq(opt,p,maxfev=10000,epsfcn=1e-5)
    #fit = {'coeff':numpy.atleast_2d(coeff[:-1]).T,'type':'polynomial'}
    #dwave = sf.genfunc(xvals,0.,fit)
    dwave = numpy.linspace(blue, red, data.size)
    dr = IDSpectrum(data, sky, dwave, wave, skymodel)
    print "dr.keyid:", dr.keyid
    print "dr.soln:", dr.soln

    x = numpy.arange(sky.size)
    w = sf.genfunc(x, 0., dr.soln)

    if dr.soln is None:
        dr.do_fit()
    xdata = dr.data.get_xdata()
    ydata = dr.data.get_ydata()
    return dr.soln
    def plot3d(self, figsize=(8, 6)):

        # the fourth dimention is color
        color_dimension = (self.stds * 100)  # the fourth dimension
        minn, maxx = color_dimension.min(), color_dimension.max()
        norm = _mpl.colors.Normalize(minn, maxx)
        m = _plt.cm.ScalarMappable(norm=norm, cmap='jet')
        m.set_array([])
        fcolors = m.to_rgba(color_dimension)

        fig = _plt.figure(figsize=figsize)
        ax = fig.gca(projection='3d')

        _plt.title("Optiimzation 4D Plot (color = 4th dimention)\n",
                   fontsize=14, fontweight="bold", color="black")
        surface = ax.plot_surface(self.sharpes, self.drawdowns*100, self.cagrs*100,
                                  linewidth=0., antialiased=True,
                                  facecolors=fcolors, vmin=minn, vmax=maxx,
                                  rstride=1, cstride=1)

        cbar = _plt.colorbar(m, shrink=0.7)
        cbar.ax.yaxis.set_major_formatter(_plt.FormatStrFormatter(' %.2f '))
        cbar.set_label("Volatility", fontweight="bold", color="black")

        ax.grid(True)
        ax.xaxis.pane.set_edgecolor('silver')
        ax.yaxis.pane.set_edgecolor('silver')
        # ax.zaxis.pane.set_edgecolor('silver')

        # ax.xaxis.pane.fill = False
        # ax.yaxis.pane.fill = False
        # ax.zaxis.pane.fill = False

        ax.xaxis.set_major_formatter(_plt.FormatStrFormatter(' %.2f '))
        ax.set_xlabel('\nSharpe', fontweight="bold", color="black")
        ax.yaxis.set_major_formatter(_plt.FormatStrFormatter(' %.f%% '))
        ax.set_ylabel('\n\nDrawdown', fontweight="bold", color="black")
        ax.zaxis.set_major_formatter(_plt.FormatStrFormatter('  %.f%% '))
        ax.set_zlabel('\nCAGR', fontweight="bold", color="black")

        try:
            _plt.subplots_adjust(hspace=0)
        except Exception:
            pass
        try:
            fig.tight_layout()
        except Exception:
            pass

        _plt.show()
Beispiel #19
0
 def plotuncertanty(self, name='preduncer'):
     fraction = 0.5
     width = 510
     timex = 2000
     y = np.concatenate((self.y_train[-timex:], self.yqcnn), axis=0)
     #self.y_test[91]=9.06
     fig, ax = plt.subplots(figsize=set_size(width, fraction), sharey='all')
     #plt.plot(self.y_train[-timex:],'grey', label='fitted model')
     plt.plot(y + 0.1, 'red', label='ground truth', alpha=0.9)
     ax.fill_between(range(timex,
                           len(self.y_test) + timex),
                     self.yqcnnl,
                     self.yqcnnu - 0.5,
                     color='royalblue',
                     alpha=0.5,
                     label='predictive uncertainty')
     plt.plot(range(timex,
                    len(self.y_test) + timex),
              self.y_test + 0.1,
              'orange',
              label='fitted model',
              alpha=0.8)
     ax.axvline(x=timex,
                ymin=0,
                ymax=5,
                color='grey',
                ls='--',
                lw=2,
                alpha=0.7)
     #plt.scatter(timex+91, self.y_test[91], marker='*', s=70, color='red', label='predicted extreme event')#extreme event
     #ax.grid(True, zorder=5)
     #plt.plot(self.y_test, color='olive', alpha=0.8, label ='ground truth')
     #plt.plot(range(timex,len(self.y_test)+timex), self.yqlstm[0],color='grey',alpha=0.3)
     #plt.plot(range(timex,len(self.y_test)+timex), self.yqlstm[2],color='grey',alpha=0.3)
     plt.ylim([8.8, 10.2])
     ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
     ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
     ax.xaxis.set_major_locator(plt.LinearLocator(6))
     ax.yaxis.set_major_locator(plt.LinearLocator(6))
     plt.legend(loc='upper right',
                bbox_to_anchor=(0.75, 1.03),
                ncol=1,
                columnspacing=0.05)
     ax.set_xlabel('Time ')
     ax.set_ylabel(r'EDF stock price (\pounds)')
     plt.tight_layout()
     plt.savefig('../_8th/myphd/thesis_1/figures/' + name + '.pdf',
                 format='pdf',
                 bbox_inches='tight')
Beispiel #20
0
 def plot(self):
     fig, ax = plt.subplots(1, 1)
     ax.set_ylabel("Loss")
     ax.set_xlabel("Learning Rate (log scale)")
     ax.set_xscale("log")
     ax.xaxis.set_major_formatter(plt.FormatStrFormatter("%.0e"))
     ax.plot(self.lrs, self.losses)
Beispiel #21
0
    def plot_learning_rate(
        self, file_name: Union[str, Path], skip_first: int = 10, skip_last: int = 5
    ):
        if type(file_name) is str:
            file_name = Path(file_name)

        lrs, losses = self._extract_learning_rate(file_name)
        lrs = lrs[skip_first:-skip_last] if skip_last > 0 else lrs[skip_first:]
        losses = losses[skip_first:-skip_last] if skip_last > 0 else losses[skip_first:]

        fig, ax = plt.subplots(1, 1)
        ax.plot(lrs, losses)
        ax.set_ylabel("Loss")
        ax.set_xlabel("Learning Rate")
        ax.set_xscale("log")
        ax.xaxis.set_major_formatter(plt.FormatStrFormatter("%.0e"))

        # plt.show()

        # save plot
        plt.tight_layout(pad=1.0)
        path = file_name.parent / "learning_rate.png"
        plt.savefig(path, dpi=300)
        print(
            f"Learning_rate plots are saved in {path}"
        )  # to let user know the path of the save plots
        plt.show(block=True)  # to have the plots displayed when user run this module
        plt.close(fig)
Beispiel #22
0
    def plot_learning_rate(self,
                           file_name: Union[str, Path],
                           skip_first: int = 10,
                           skip_last: int = 5):
        if type(file_name) is str:
            file_name = Path(file_name)

        lrs, losses = self._extract_learning_rate(file_name)
        lrs = lrs[skip_first:-skip_last] if skip_last > 0 else lrs[skip_first:]
        losses = losses[skip_first:-skip_last] if skip_last > 0 else losses[
            skip_first:]

        fig, ax = plt.subplots(1, 1)
        ax.plot(lrs, losses)
        ax.set_ylabel("Loss")
        ax.set_xlabel("Learning Rate")
        ax.set_xscale("log")
        ax.xaxis.set_major_formatter(plt.FormatStrFormatter("%.0e"))

        # save plot
        plt.tight_layout(pad=1.0)
        path = file_name.parent / "learning_rate.png"
        plt.savefig(path, dpi=300)

        plt.close(fig)
def plot_cost_function(cost_function, x_range, y_range, resolution, point1, point2):
    x = np.arange(x_range[0], x_range[1], resolution)
    y = np.arange(y_range[0], y_range[1], resolution)

    X, Y = np.meshgrid(x, y)
    Z = np.vectorize(cost_function)(X, Y)

    fig = plt.figure()
    fig.suptitle(r'Cost function with $\theta = 0$')
    ax = fig.gca(projection='3d')
    surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.cm.RdBu, linewidth=0, antialiased=False)
    ax.zaxis.set_major_locator(plt.LinearLocator(10))
    ax.zaxis.set_major_formatter(plt.FormatStrFormatter('%.02f'))

    ax.set_xlabel('x-position')
    ax.set_ylabel('y-position')
    ax.set_zlabel('cost function')
    ax.view_init(elev=25, azim=-120)

    fig.colorbar(surf, shrink=0.5, aspect=5)

    # Plot 2D
    fig = plt.figure()
    im = plt.imshow(Z, cmap=plt.cm.RdBu)
    cset = plt.contour(Z, [cost_function(point1[0], point1[1]), cost_function(point2[0], point2[1])],
                       linewidths=2, cmap=plt.cm.Set2)
    plt.clabel(cset, inline=True, fmt='%1.1f', fontsize=10)
    plt.colorbar(im)
Beispiel #24
0
 def plot(self):
     fig, ax = plt.subplots(1, 1)
     ax.set_ylabel('Loss')
     ax.set_xlabel('Learning Rate (log scale)')
     ax.set_xscale('log')
     ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0e'))
     ax.plot(self.lrs, self.losses)
Beispiel #25
0
    def __init__(self, weather_data, day_number, parent=None):
        super(Hourly_Plot_Widget, self).__init__(parent)
        self.weather_data = weather_data
        self.day_number = day_number

        figure = Figure()
        canvas = FigureCanvasQTAgg(figure)

        axis_rain = figure.add_subplot(111)
        axis_rain.set(ylabel='opady[mm]', title='Pogoda godzinowa')
        axis_rain.xaxis.set_major_locator(plt.MaxNLocator(10))
        axis_rain.xaxis.set_major_formatter(plt.FormatStrFormatter('%d:00'))
        axis_rain.set_ylim(0, 20)

        axis_temp = axis_rain.twinx()
        axis_temp.set(ylabel='temperatura [C]')
        axis_temp.yaxis.set_major_locator(plt.MultipleLocator(5))

        x = self.create_x_dataset()
        y_temp = self.create_temp_dataset()
        y_rain = self.create_rain_dataset()

        axis_rain.bar(x, y_rain, color='#B3FFFF')
        axis_temp.plot(x, y_temp, 'ro-')

        axis_temp.set_ylim(axis_temp.get_ylim()[0] - 2,
                           axis_temp.get_ylim()[1] + 2)

        for i in range(0, len(x)):
            axis_temp.annotate(y_temp[i], (x[i], y_temp[i] + 1))

        self.layoutVertical = QVBoxLayout(self)
        self.layoutVertical.addWidget(canvas)
Beispiel #26
0
    def _show_lr_plot(self,
                      index,
                      losses_skipped=losses_skipped,
                      trailing_losses_skipped=trailing_losses_skipped):
        import matplotlib.pyplot as plt
        fig, ax = plt.subplots(1, 1)
        losses = self.learn.recorder.losses
        lrs = self.learn.recorder.lrs
        final_losses_skipped = 0
        if len(self.learn.recorder.
               losses[losses_skipped:-trailing_losses_skipped]) >= 5:
            losses = self.learn.recorder.losses[
                losses_skipped:-trailing_losses_skipped]
            lrs = self.learn.recorder.lrs[
                losses_skipped:-trailing_losses_skipped]
            final_losses_skipped = losses_skipped
        ax.plot(lrs, losses)
        ax.set_ylabel("Loss")
        ax.set_xlabel("Learning Rate")
        ax.set_xscale('log')
        ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.0e'))
        ax.plot(self.learn.recorder.lrs[index],
                self.learn.recorder.losses[index],
                markersize=10,
                marker='o',
                color='red')

        plt.show()
Beispiel #27
0
    def test_isotropy(self):
        fig, ax = plt.subplots(nrows=1, ncols=1)
        #ax.set_aspect('equal')
        ax.scatter(self.cond_angle[:] / np.pi,
                   self.cond_e_min,
                   label='C min eigv',
                   s=0.5,
                   c='blue')
        ax.scatter(self.cond_angle[:] / np.pi,
                   self.cond_e_max,
                   label='C max eigv',
                   s=0.5,
                   c='orange')

        angle = np.linspace(0, np.pi, 200)
        vec = np.stack([np.cos(angle), np.sin(angle)], axis=0)
        mean_flux = self.mean_c_tn @ vec

        ax.plot(angle / np.pi,
                np.linalg.norm(mean_flux, axis=0),
                label='|C_mean * vec(angle)|',
                color='orange',
                linewidth=2)
        Y = np.full_like(angle, 1e-10)
        ax.plot(angle / np.pi, Y, label='C bulk', color='red', linewidth=2)
        ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%g $\pi$'))
        import matplotlib
        ax.xaxis.set_major_locator(
            matplotlib.ticker.MultipleLocator(base=0.25))
        ax.set_ylim(np.min(self.cond_e_min), np.max(self.cond_e_max))
        ax.set_yscale('log')
        ax.legend()
        fig.suptitle("Isotropy  of the conductivity field")
        fig.savefig("isotropy.pdf")
        plt.close(fig)
Beispiel #28
0
def plot(bench, filename):
    def function(x1, x2):
        vec = bench.function()
        return vec(2, [x1, x2])

    plotN = 100
    x1 = np.linspace(bench.Lower, bench.Upper, plotN)
    x2 = np.linspace(bench.Lower, bench.Upper, plotN)

    x1, x2 = np.meshgrid(x1, x2)

    vecFunction = np.vectorize(function)
    z = vecFunction(x1, x2)

    fig = plt.figure()

    ax = fig.gca(projection='3d')
    surf = ax.plot_surface(x1,
                           x2,
                           z,
                           rstride=1,
                           cstride=1,
                           cmap=plt.cm.rainbow,
                           linewidth=0,
                           antialiased=False)
    fig.colorbar(surf, shrink=0.5, aspect=7, cmap=plt.cm.coolwarm)

    ax.zaxis.set_major_locator(plt.LinearLocator(10))
    ax.zaxis.set_major_formatter(plt.FormatStrFormatter('%.01f'))

    plt.savefig(filename)
Beispiel #29
0
    def numberDaysPlot(code, daysNumbers, volume=500):
        """
         静态方法,获取连续n天的大单数量,并统计分析画图
        :param code:股票代码
        :param daysNumbers:天数,以当前日期往前推
        :param volume:大单
        :return:
        """
        #获取起始日期
        startDay = tls.getday(-daysNumbers)
        dayIndex = pd.date_range(startDay, periods=daysNumbers + 1)
        buylist = []
        selllist = []
        daylist = []
        stockname = " "
        for day in dayIndex:
            bd = Bigdeal(code, day, volume)
            if bd.isOpen == True:
                stockname = bd.stockname
                #换算为万元
                buySum = bd.getTotalBuy() / 10000
                sellSum = bd.getTotalSell() / 10000
                buylist.append(buySum)
                selllist.append(sellSum)
                d = day.__str__().split(' ')[0]
                daylist.append(d)

        ax = plt.subplot(111)
        x = np.arange(0, len(daylist))
        x1 = x * 2.5
        x2 = x1 + 1
        plt.bar(left=x1, height=buylist, width=1, color='red')
        plt.hold
        plt.bar(left=x2, height=selllist, width=1, color='green')

        plt.xticks(x2, daylist)
        plt.legend(['buy', 'sell'],
                   loc='upper center',
                   fancybox=True,
                   shadow=True)
        ax.get_yaxis().set_major_formatter(plt.FormatStrFormatter('%i'))
        # plt.setp(ax.get_xaxis().get_majorticklabels(), rotation=-45)
        myfont = matplotlib.font_manager.FontProperties(fname="msyhbd.ttf")
        yl = u'单位(万元)'
        plt.ylabel(yl, fontproperties=myfont)

        title = u"%s在%d日内超过%d手的大单交易量" % (stockname, daysNumbers, volume)
        plt.title(title, fontproperties=myfont)

        money = round(sum(buylist) - sum(selllist))
        strMoney = u"%s在%s日超过%d手的大单净流入人民币%d万元" % (stockname, daysNumbers,
                                                  volume, money)
        if money < 0:
            strMoney = u"%s在%s日超过%d手的大单净流出人民币%d万元" % (stockname, daysNumbers,
                                                      volume, money)
        textx = x2[0]
        texty = max([max(buylist), max(selllist)]) * 6 / 8
        plt.text(textx, texty, strMoney, fontproperties=myfont)

        plt.show()
Beispiel #30
0
def plot_distr(binned_data_list,binning_increment):
	norm_concs = []
	bin_mids = []
	for row in binned_data_list:
		bin_mid = row[0]
		bin_conc = row[1]
		bin_conc_norm = bin_conc/(math.log(bin_mid+binning_increment/2.,10)-math.log(bin_mid-binning_increment/2.,10))
		norm_concs.append(bin_conc_norm)
		bin_mids.append(bin_mid)


	popt,perr = SP2_utilities.fitFunction(SP2_utilities.lognorm,bin_mids,norm_concs,p0=(100,180,0.5))

	fit_bin_mids = np.arange(10,1000,5)
	fit_concs = []
	for fit_bin_mid in fit_bin_mids:
		fit_conc_norm  = SP2_utilities.lognorm(fit_bin_mid, popt[0], popt[1], popt[2])
		fit_concs.append(fit_conc_norm)
	
	
	ticks = [10,20,30,40,50,60,80,120,200,300,400,600,1000]
	fig = plt.figure()
	ax1 = fig.add_subplot(111)
	ax1.plot(fit_bin_mids,fit_concs)
	ax1.scatter(bin_mids,norm_concs)
	ax1.xaxis.set_major_formatter(plt.FormatStrFormatter('%d'))
	ax1.xaxis.set_major_locator(plt.FixedLocator(ticks))
	ax1.set_xscale('log')
	ax1.set_xlim(10,1000)
	ax1.set_ylabel('dM/dlogD (ng/m3)')
	ax1.set_xlabel('rBC VED (nm)')
	plt.show()