Ejemplo n.º 1
0
def plot_matplotlib(sample, base_name):
    colors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00']

    params = { 'figure.facecolor': 'white',
               'figure.subplot.bottom': 0.0,
               'font.size': 16, 
               'legend.fontsize': 16,
               'legend.borderpad': 0.2,
               'legend.labelspacing': 0.2,
               'legend.handlelength': 1.5,
               'legend.handletextpad': 0.4,
               'legend.borderaxespad': 0.2,
               'lines.markeredgewidth': 2.0,
               'lines.linewidth': 2.0,
               'axes.prop_cycle': plt.cycler('color',colors)}
    plt.rcParams.update(params)

    fig, ax = plt.subplots(2)
    ax[0].hist(sample[met_pred_parameter], 50, range=(0.0, 400.0), label='Pred', histtype='step')
    ax[0].hist(sample[met_reco_parameter], 50, range=(0.0, 400.0), label='Obs', histtype='step')
    ax[0].hist(sample[met_target_parameter], 50, range=(0.0, 400.0), label='Target', histtype='step')
    ax[0].set_xlim([0,400])
    ax[0].set_xlabel("pT (GeV)")
    ax[0].legend(loc='upper right')

    ax[1].hist(sample[met_pred_resolution], 50, range=(-100.0, 100.0), label='Pred', histtype='step')
    ax[1].hist(sample[met_reco_resolution], 50, range=(-100.0, 100.0), label='Obs', histtype='step')
    ax[1].set_xlim([-100,100])
    ax[1].set_xlabel("Resolution (%)")
    ax[1].legend(loc='upper left')

    fig.tight_layout(pad=0.3)
    fig.savefig('{}.pdf'.format(base_name))
    plt.show()
Ejemplo n.º 2
0
    def test_get_color_cycle(self):

        if mpl_ge_150:
            colors = [(1., 0., 0.), (0, 1., 0.)]
            prop_cycle = plt.cycler(color=colors)
            with plt.rc_context({"axes.prop_cycle": prop_cycle}):
                result = utils.get_color_cycle()
                assert result == colors
def generate_feature_graph_for_repo(repo_count):

	plt.rc('axes', prop_cycle=(plt.cycler('color', ['r', 'g', 'b', 'k']) + plt.cycler('linestyle', ['--', '--', '--', '--'])))
	for per in xrange(1,5):

		data = None
		data = pd.read_csv('./features/repo_'+str(repo_count)+'_person_'+str(per)+'_uneven_person_commits.csv', sep=',', )

		max_bins = data['Week_No'].max()

		plt.plot(data['Week_No'], data['Commit_Count'], label="Person" + str(per))

	
	plt.ylabel('Commit Count Per Person')
	plt.xlabel('Week Number')
	plt.title('Early Commit Smoke Per Person for Repo ' + str(repo_count))
	plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=1, ncol=4, mode="expand", borderaxespad=0.)

	plt.savefig('./results/repo_'+str(repo_count)+'_early_commit_smoke.png')
	plt.close()
Ejemplo n.º 4
0
def setup(dpi=300, sketch=(1, 100, 2), theme='light'):
    """Setup travelmaps."""
    # Customized plt.xkcd()-settings
    # http://jakevdp.github.io/blog/2013/07/10/XKCD-plots-in-matplotlib
    rcParams['font.family'] = ['Humor Sans', 'Comic Sans MS']
    rcParams['font.size'] = 8.0
    rcParams['path.sketch'] = sketch
    rcParams['axes.linewidth'] = 1.0
    rcParams['lines.linewidth'] = 1.0
    rcParams['grid.linewidth'] = 0.0
    rcParams['axes.unicode_minus'] = False
    if theme=='dark':
        rcParams['path.effects'] = [patheffects.withStroke(linewidth=2, foreground="k")]
        rcParams['figure.facecolor'] = 'black'
        rcParams['figure.edgecolor'] = 'black'
        rcParams['lines.color'] = 'white'
        rcParams['patch.edgecolor'] = 'white'
        rcParams['text.color'] = 'white'
        rcParams['axes.facecolor'] = 'black'
        rcParams['axes.edgecolor'] = 'white'
        rcParams['axes.labelcolor'] = 'white'
        rcParams['xtick.color'] = 'white'
        rcParams['ytick.color'] = 'white'
        rcParams['grid.color'] = 'white'
        rcParams['savefig.facecolor'] = 'black'
        rcParams['savefig.edgecolor'] = 'black'
        
    else:
        rcParams['path.effects'] = [patheffects.withStroke(linewidth=2, foreground="w")]
        rcParams['figure.facecolor'] = 'white'
        rcParams['figure.edgecolor'] = 'white'
        rcParams['lines.color'] = 'black'
        rcParams['patch.edgecolor'] = 'black'
        rcParams['text.color'] = 'black'
        rcParams['axes.facecolor'] = 'white'
        rcParams['axes.edgecolor'] = 'black'
        rcParams['axes.labelcolor'] = 'black'
        rcParams['xtick.color'] = 'black'
        rcParams['ytick.color'] = 'black'
        rcParams['grid.color'] = 'black'
        rcParams['savefig.facecolor'] = 'white'
        rcParams['savefig.edgecolor'] = 'white'

    # *Bayesian Methods for Hackers*-colour-cylce
    # (https://github.com/pkgpl/PythonProcessing/blob/master/results/matplotlibrc.bmh.txt)
    rcParams['axes.prop_cycle'] = plt.cycler('color', ['#348ABD', '#A60628', '#7A68A6', '#467821', '#D55E00',
                                     '#CC79A7', '#56B4E9', '#009E73', '#F0E442', '#0072B2'])

    # Adjust dpi, so figure on screen and savefig looks the same
    rcParams['figure.dpi'] = dpi
    rcParams['savefig.dpi'] = dpi
Ejemplo n.º 5
0
def set_palette(name=None, num_colors=8, start=0):
    """Set the active color palette

    Parameters
    ----------
    name : str, optional
        Name of the palette. If `None`, modify the active palette.
    num_colors : int
        Number of colors to retrieve.
    start : int
        Staring from this color number.
    """
    palette = get_palette(name, num_colors, start)
    mpl.rcParams["axes.prop_cycle"] = plt.cycler('color', palette)
    mpl.rcParams["patch.facecolor"] = palette[0]
Ejemplo n.º 6
0
def plot_energies_on_plane(folder_loc):
    """
    Plot Poincare 3D surface on a 2D plane with the colour of the plane defined
    by the energy of that point. 
    """
    cm = plt.cm.viridis
    plt.gca().set_prop_cycle(
        plt.cycler('color', cm(np.linspace(0, 1, len(range(470))))))
    t = [0.1 * i for i in range(1200)]
    for i in range(1, 550):
        try:
            with open(folder_loc + f"results_{i}.yml") as f:
                data = yaml.load(f, Loader=yaml.Loader)
        except:
            continue

        result = data['data']
        energies = apply_energy(result)
        mod_θ2 = centre_plane(result[:, 0])
        x_points = find_crossing_points(mod_θ2)
        es = []
        ϕ1s = []
        ϕ2s = []
        θ2s = []
        for x in x_points:
            f1, f2, f3, f4 = interpolate_functions(x[0], t, result)
            t0 = find_zero(x[0], t, f1)
            ϕ1_0 = f2(t0)
            ϕ2_0 = f3(t0)
            θ2_0 = f4(t0)

            es.append(energies[x[0]])
            ϕ1s.append(ϕ1_0)
            ϕ2s.append(ϕ2_0)
            θ2s.append(θ2_0)

        plt.scatter(np.mod(np.array(ϕ1s), np.pi * 2),
                    np.mod(np.array(θ2s), np.pi * 2),
                    c=es,
                    s=0.5)
    plt.colorbar()
    plt.show()
def plot_displacement_all(filenames):
    fig = plt.figure(figsize=(6, 6), dpi=80, facecolor='w', edgecolor='k')
    ax = fig.add_subplot(111)
    displacement = np.loadtxt(filenames[0], delimiter=',')
    plt.set_cmap(plt.get_cmap('winter'))
    plt.gca().set_prop_cycle(
        plt.cycler('color', plt.cm.jet(np.linspace(0.1, 0.9, len(filenames)))))
    xmax = 0
    for filename in filenames:
        xmax = max(xmax, np.loadtxt(filename, delimiter=',')[:, 0][-1])
    ax.set_xlim(left=0.01, right=xmax)
    # ax.set_ylim(bottom=100, top=10000000)
    plt.xlabel('$t [s]$')
    plt.ylabel('$< \Delta r^2 > [\mu m^2]$')
    plt.yscale('log')
    plt.xscale('log')
    for filename in filenames:
        displacement = np.loadtxt(filename, delimiter=',')
        time = list(displacement[:, 0][:100])
        disp = list(displacement[:, 1][:100])
        i = 0
        while 101 + int(pow(1.05, i)) < len(displacement[:, 0]):
            time.append(displacement[:, 0][101 + int(pow(1.05, i))])
            disp.append(
                sum(displacement[:, 1][100 + int(pow(1.05, (i - 1))):101 +
                                       int(pow(1.05, i))]) /
                (1 + int(pow(1.05, i)) - int(pow(1.05, (i - 1)))))
            i += 1
        time.append(displacement[:, 0][-1])
        disp.append(
            sum(displacement[:, 1][100 + int(pow(1.05, (i - 1))):]) /
            (len(displacement[:, 1]) - int(pow(1.05, (i - 1)))))
        plt.plot(time, disp, alpha=0.7, label=filename[7:].split('*')[0])
        plt.legend()
    filename = filename.split(' = ')[0] + filename[:-4].split(
        ' * ')[1] + '.png'
    filename = filename.replace('\\', '')
    filename = filename.replace('$', '')
    filename = filename.replace('{', '')
    filename = filename.replace('}', '')
    filename = filename.replace(' ', '')
    plt.savefig(filename, bbox_inches='tight')
def visualize_results(file_name, title_name, graph_type, type_weights,
                      fin_normalized_load, fin_approx_h1, fin_approx_h2,
                      fin_h1, fin_h2):

    fig, ax = plt.subplots()
    ax.set_prop_cycle(
        plt.cycler('color', ['black', 'saddlebrown', '#ff3232', 'gold']))

    ax.plot(fin_normalized_load,
            fin_approx_h1,
            'v-',
            linewidth=1.7,
            label='local-ratio ' + r'$h_1$')
    ax.plot(fin_normalized_load,
            fin_h1,
            's--',
            linewidth=1.5,
            dashes=[5, 5, 5, 5],
            label=r'$h_1$')
    ax.plot(fin_normalized_load,
            fin_approx_h2,
            'o-',
            linewidth=1.7,
            label='local-ratio ' + r'$h_1$')
    ax.plot(fin_normalized_load,
            fin_h2,
            'd--',
            linewidth=1.5,
            dashes=[5, 5, 5, 5],
            label=r'$h_2$')

    ax.legend(loc='upper left')
    ax.set_xlabel('normalized load')
    ax.set_ylabel(title_name)
    ax.set_xticklabels(labels=[], minor=True)
    ax.set_title(title_name)
    ax.set_yscale("log")

    plt.draw()
    plt.pause(5)
    plt.savefig('plots/' + graph_type + "/" + type_weights + "/" + file_name +
                '.pdf')
def plot_density_all(filenames):
    fig = plt.figure(figsize=(8, 4), dpi=80, facecolor='w', edgecolor='k')
    ax = fig.add_subplot(111)
    plt.xlabel('')
    plt.ylabel('')
    plt.set_cmap(plt.get_cmap('winter'))
    plt.gca().set_prop_cycle(
        plt.cycler('color', plt.cm.jet(np.linspace(0.1, 0.9, len(filenames)))))
    for filename in filenames:
        concentration = np.loadtxt(filename, delimiter=',')
        plt.plot(concentration, alpha=0.7, label=filename[7:].split('*')[0])
        plt.legend()
    filename = filename.split(' = ')[0] + filename[:-4].split(
        ' * ')[1] + '.png'
    filename = filename.replace('\\', '')
    filename = filename.replace('$', '')
    filename = filename.replace('{', '')
    filename = filename.replace('}', '')
    filename = filename.replace(' ', '')
    plt.savefig(filename, bbox_inches='tight')
Ejemplo n.º 10
0
def set_palette(*args, **kwds):
    """Set the matplotlib color cycler.

    args, kwds: same as for sns.color_palette

    Also takes a boolean kwd, `reverse`, to indicate
    whether the order of the palette should be reversed.

    returns: list of colors
    """
    reverse = kwds.pop('reverse', False)
    palette = sns.color_palette(*args, **kwds)

    palette = list(palette)
    if reverse:
        palette.reverse()

    cycler = plt.cycler(color=palette)
    plt.gca().set_prop_cycle(cycler)
    return palette
Ejemplo n.º 11
0
def set_style(style='blackviz'):
    plt.rc('figure', facecolor='0.065', autolayout=False, dpi=120)
    plt.rc('axes',
           facecolor='0.125',
           edgecolor='w',
           grid=True,
           labelcolor='lightgrey',
           labelsize='large',
           prop_cycle=plt.cycler('color', [
               'deepskyblue', 'orangered', 'green', 'yellow', 'mintcream',
               'magenta', 'darkorange'
           ]))

    plt.rc('xtick', color='w')
    plt.rc('ytick', color='w')
    plt.rc('grid', color='w', linestyle='-', alpha=0.25)
    plt.rc('font', size=12)
    plt.rc('text', color='lightgrey')
    plt.rc('lines', linewidth=2)
    plt.rc('figure', figsize='10, 8', titlesize='x-large')
Ejemplo n.º 12
0
 def set_draw_settings(self):
     params = {
         "figure.facecolor":
         "#cad9e1",
         "axes.facecolor":
         "#cad9e1",
         "axes.grid":
         True,
         "axes.grid.axis":
         "y",
         "grid.color":
         "#ffffff",
         "grid.linewidth":
         2,
         "axes.spines.left":
         False,
         "axes.spines.right":
         False,
         "axes.spines.top":
         False,
         "ytick.major.size":
         0,
         "ytick.minor.size":
         0,
         "xtick.direction":
         "in",
         "axes.titlesize":
         "small",
         "xtick.major.size":
         7,
         "xtick.color":
         "#191919",
         "axes.edgecolor":
         "#191919",
         "axes.prop_cycle":
         plt.cycler('color', [
             '#006767', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd',
             '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'
         ])
     }
     plt.rcParams.update(params)
Ejemplo n.º 13
0
def rmse_time(al_rmse, avg_sim_time, n_node, hop_lim, n_trial, results_path):
    plt.style.use('bmh')
    plt.rcParams['axes.prop_cycle'] = plt.cycler(color=plt.cm.Paired.colors)
    plt.rcParams['font.sans-serif'] = 'Arial'

    fig, ax = plt.subplots(figsize=(16, 8))
    x = range(1, n_trial + 1)
    # all_rmse = [1000*i for i in al_rmse]

    x_ticks = list(range(0, n_trial + 1, 10))

    ticks = [1, '', '', '', '', '', '', '', '', '']
    for i in range(1, -(-n_trial // 10)):
        sub_ticks = [i * 10, '', '', '', '', '', '', '', '', '']
        ticks += sub_ticks
    ticks = ticks[:n_trial]

    ax.plot(x, al_rmse, color='C1', linewidth=1)
    ax.set_xlabel('Trial #', fontsize=11)
    ax.set_ylabel("Average RMSE [km]", fontsize=11)
    ax.grid(axis='x')
    ax.set_axisbelow(True)
    ax.set_title(f'{n_node} Node Network RMSE', {'fontsize': 13})
    ax.set_xlim(0, n_trial + 1)
    ax.set_ylim(min(al_rmse) * .5, max(al_rmse) * 1.1)
    ax.set_xticks(x_ticks)
    # ax.xaxis.set_ticklabels([str(i) for i in list(x)])
    mean = r'$\mu_{rmse} = $' + f"{np.mean(al_rmse):.2f} km" + '\n' + \
           r'$\mu_{sim time} = $' + f"{avg_sim_time:.2f} s"
    ax.text(.98,
            .90,
            mean,
            transform=ax.transAxes,
            va='baseline',
            fontsize=11,
            ha='right',
            bbox=dict(facecolor='C0', edgecolor='k', alpha=.6))

    fig.savefig(f'{results_path}/{hop_lim}hop_{n_trial}sim_rmse-refine.png',
                dpi=200)
    plt.show()
Ejemplo n.º 14
0
def _make_style():
    nearly_black = '0.15'
    linewidth = 0.6
    dpi = 160
    palette = list(get_palette('Set1'))
    palette[5] = list(get_palette('Set2'))[5]

    defaults = mpl_style.library['classic']
    style = {
        'lines.solid_capstyle': 'round',  # [projecting] butt|round|projecting
        'font.size': 7.0,  # [12.0]
        'text.color': nearly_black,  # [black]
        'mathtext.default': 'regular',  # [it] the default font to use for math.
        'axes.edgecolor': nearly_black,  # [black] axes edge color
        'axes.linewidth': linewidth,  # [1.0] edge linewidth
        'axes.labelcolor': nearly_black,  # [black]
        'axes.unicode_minus': False,  # [True] use unicode for the minus symbol
        'axes.prop_cycle': plt.cycler('color', palette),  # ['bgrcmyk']
        'patch.facecolor': palette[1],  # [b]
        'xtick.major.size': 2.5,  # [4] major tick size in points
        'xtick.minor.size': 1.0,  # [2] minor tick size in points
        'xtick.major.width': linewidth,  # [0.5] major tick width in points
        'xtick.color': nearly_black,  # [black] color of the tick labels
        'ytick.major.size': 2.5,  # [4] major tick size in points
        'ytick.minor.size': 1.0,  # [2] minor tick size in points
        'ytick.major.width': linewidth,  # [0.5] major tick width in points
        'ytick.color': nearly_black,  # [black] color of the tick labels
        'legend.fancybox': True,  # [False] Use a rounded box for the legend
        'legend.numpoints': 1,  # [2] the number of points in the legend line
        'legend.fontsize': 'medium',  # ['large']
        'legend.framealpha': 0.9,  # [None] opacity of of legend frame
        'figure.figsize': (3.4, 2.8),  # [(8, 6) inch] (3.4, 2.8) inch == (8.6, 7.1) cm
        'figure.dpi': dpi,  # [80] figure dots per inch
        'figure.facecolor': 'white',  # [0.75] figure facecolor
        'image.cmap': 'viridis',  # [jet...]
        'savefig.dpi': dpi,  # [100] figure dots per inch
        'savefig.bbox': 'tight',  # ['standard']
        'savefig.pad_inches': 0.04,  # [0.1] padding to be used when bbox is set to 'tight'
    }

    return with_defaults(style, defaults)
Ejemplo n.º 15
0
def plot_insulation(clr, insulation, windows, resolution, out_path, exclude_chroms, title):
    dir_path = os.path.join(os.path.dirname(out_path), title)

    if not os.path.exists(dir_path):
        os.mkdir(dir_path)

    chromsizes = bioframe.fetch_chromsizes('sacCer3', filter_chroms=False)
    regions = [(k, 0, v) for k, v in chromsizes.drop('chrM').iteritems()]

    for region in regions:
        norm = LogNorm(vmax=0.1, vmin=0.001)
        data = clr.matrix(balance=True).fetch(region)
        fig, ax = plt.subplots(figsize=(20, 4))

        img = plot_45_mat(ax, data, start=0, resolution=resolution, norm=norm, cmap='fall')

        ax.set_aspect(0.5)
        ax.set_ylim(0, 30000)
        format_ticks(ax, rotate=False)
        ax.xaxis.set_visible(False)

        divider = make_axes_locatable(ax)
        cax = divider.append_axes('right', size='1%' ,pad=0.1, aspect=6)
        plt.colorbar(img, cax=cax)

        insul_region = bioframe.select(insulation, region)
        
        ins_ax = divider.append_axes('bottom', size='50%', pad=0.0, sharex=ax)
        ins_ax.set_prop_cycle(plt.cycler('color', plt.cm.plasma(np.linspace(0, 1, 5))))

        for window in windows:
            ins_ax.plot(insul_region[['start', 'end']].mean(axis=1),
                insul_region[f'log2_insulation_score_{window}'],
                label=f'{window} bp window', lw=1)

        ins_ax.legend(bbox_to_anchor=(1.125, 1.05), loc='upper right')
        fig.suptitle(f'{title}: {region[0]}')

        path = os.path.join(dir_path, '_'.join((region[0], os.path.basename(out_path))))

        plt.savefig(path, dpi=300)
Ejemplo n.º 16
0
def time_plot2(df, sample_name, labels):
    # Initialise figure
    fig, ax = plt.subplots(figsize=(16, 4))
    ax.plot(df)

    # Define colour space for lines
    colourmap = plt.cm.gist_ncar
    plt.gca().set_prop_cycle(
        plt.cycler('color', plt.cm.jet(np.linspace(0, 0.9, 9))))

    # Set up layout
    ax.set(xlabel='time steps',
           ylabel='signal (analog counts)',
           title='data sample: ' + sample_name)
    ax.legend(labels)
    ax.grid()

    #     fig.savefig("data/figures/"+sample_name+"_timeplot.png")
    plt.show()

    return
Ejemplo n.º 17
0
 def plot(self, var_to_plot=None):
     if var_to_plot is None:
         var_to_plot = self.labels
     fig = plt.figure()
     ax = fig.add_subplot(111)
     ax.set_prop_cycle(
         plt.cycler('color', ['r', 'g', 'b', 'c', 'm', 'y', 'k']))
     handles = []
     labels = []
     for v in var_to_plot:
         try:
             i = self.labels.index(v)
             h, = ax.plot(self.time, self.data[:, i])
             handles.append(h)
             labels.append(v)
         except:
             print("Variable", v, "not found")
     fig.legend(handles, labels)
     plt.title(self.description)
     plt.xlabel('Time')
     plt.show()
Ejemplo n.º 18
0
def usePlotStyle():
    matplotlib.style.use('default')
    plt.rcParams.update({
        'figure.figsize': (20, 10),
        'font.size': 20,
        'xtick.labelsize': 18,
        'ytick.labelsize': 18,
        'axes.prop_cycle': plt.cycler(
            color=[
                Colors.orange,
                Colors.blue,
                Colors.green,
                Colors.red,
                Colors.purple,
                Colors.brown,
                Colors.pink,
                Colors.gray,
                Colors.yellow,
                Colors.turquoise
            ])
        })
Ejemplo n.º 19
0
 def cycle(self, n: str):
     if n == '0':
         return plt.cycler("color", self.schemes(
             self.parameters['scheme']))  #colors)
     elif n == '1':
         return plt.cycler("color", self.schemes(
             self.parameters['scheme'])) + plt.cycler(
                 "linestyle", self.linestyles(self.parameters['linestyle']))
     elif n == '2':
         return plt.cycler("color", self.schemes(
             self.parameters['scheme'])) * plt.cycler(
                 "linestyle", self.linestyles(self.parameters['linestyle']))
     elif n == '3':
         return plt.cycler(
             "linestyle", self.linestyles(
                 self.parameters['linestyle'])) * plt.cycler(
                     "color", self.schemes(self.parameters['scheme']))
     else:
         raise ValueError('Index out of bound')
Ejemplo n.º 20
0
def plotExTimes(execTimesDict):
    '''
    Given a dict funcname:executiontimesarray 
    plots all the functions in the same plot
    '''
    # Make a colormap to plot the lines in different colors
    # pylint: disable=no-member,unused-variable
    num_plots = len(execTimesDict)
    fig, ax = plt.subplots(figsize=(15, 3))
    plt.gca().set_prop_cycle(
        plt.cycler('color', plt.cm.gist_rainbow(np.linspace(0, 1, num_plots))))
    for fname, exTime in execTimesDict.items():
        ax.plot(exTime, label=fname)
    ax.set_xticklabels([str(i / 5.) for i in range(6)])
    ax.set_xticks([i for i in range(0, 101, 20)])
    ax.set_xlabel('u')
    ax.set_ylabel('Execution time')

    ax.legend(loc='best')

    plt.suptitle('Runtime execution times')
Ejemplo n.º 21
0
def setup_noxkcd(dpi=300, theme='light'):
    """Setup Maps."""
    if theme=='dark':
        rcParams['figure.facecolor'] = 'black'
        rcParams['figure.edgecolor'] = 'black'
        rcParams['lines.color'] = 'white'
        rcParams['patch.edgecolor'] = 'white'
        rcParams['text.color'] = 'white'
        rcParams['axes.facecolor'] = 'black'
        rcParams['axes.edgecolor'] = 'white'
        rcParams['axes.labelcolor'] = 'white'
        rcParams['xtick.color'] = 'white'
        rcParams['ytick.color'] = 'white'
        rcParams['grid.color'] = 'white'
        rcParams['savefig.facecolor'] = 'black'
        rcParams['savefig.edgecolor'] = 'black'
        
    else:
        rcParams['figure.facecolor'] = 'white'
        rcParams['figure.edgecolor'] = 'white'
        rcParams['lines.color'] = 'black'
        rcParams['patch.edgecolor'] = 'black'
        rcParams['text.color'] = 'black'
        rcParams['axes.facecolor'] = 'white'
        rcParams['axes.edgecolor'] = 'black'
        rcParams['axes.labelcolor'] = 'black'
        rcParams['xtick.color'] = 'black'
        rcParams['ytick.color'] = 'black'
        rcParams['grid.color'] = 'black'
        rcParams['savefig.facecolor'] = 'white'
        rcParams['savefig.edgecolor'] = 'white'

    # *Bayesian Methods for Hackers*-colour-cylce
    # (https://github.com/pkgpl/PythonProcessing/blob/master/results/matplotlibrc.bmh.txt)
    rcParams['axes.prop_cycle'] = plt.cycler('color', ['#348ABD', '#A60628', '#7A68A6', '#467821', '#D55E00',
                                     '#CC79A7', '#56B4E9', '#009E73', '#F0E442', '#0072B2'])

    # Adjust dpi, so figure on screen and savefig looks the same
    rcParams['figure.dpi'] = dpi
    rcParams['savefig.dpi'] = dpi
Ejemplo n.º 22
0
Archivo: cf.py Proyecto: exosports/BART
def transmittance(date_dir, atmfile, filters, plot=True):
  """
  """
  # Read atmfile
  molecules, p, T, abundances = mat.readatm(date_dir + atmfile)
  nlayers = len(p)
  p = p[::-1]  # top to bottom of the atmosphere
  # Read tau.dat
  foo      = date_dir + 'tau.dat'
  tau, wns = readTauDat(foo, nlayers)
  # Transmittance:
  transmit = np.exp(-tau)
  # Band intgrate it:
  filt_tr  = filter_cf(filters, nlayers, wns, transmit)
  nfilters = len(filters)

  colors = plt.cm.rainbow(np.asarray(np.linspace(0, 255, nfilters), np.int))
  if plot:
    print("  Plotting contribution functions.\n")
    # Not normalized cf
    plt.figure(4)
    plt.clf()
    gs       = gridspec.GridSpec(1, 2, width_ratios=[5, 1])
    ax0      = plt.subplot(gs[0])
    colormap = plt.cm.rainbow(np.linspace(0, 1, len(filters)))
    ax0.set_prop_cycle(plt.cycler('color', colormap))
    for i in np.arange(len(filt_tr)):
      (head, tail) = os.path.split(filters[i])
      lbl         = tail[:-4]
      ax0.semilogy(filt_tr[i], p, '-', linewidth = 1.5, label=lbl,
                   color=colors[i])
    lgd = ax0.legend(loc='center left', bbox_to_anchor=(1.0, 0.5), 
                     ncol=nfilters//30 + 1, prop={'size':8})
    ax0.set_ylim(max(p), min(p))
    ax0.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
    ax0.set_xlabel('Transmittance', fontsize=14)
    ax0.set_ylabel('Pressure (bar)' , fontsize=14)
    plt.savefig(date_dir + 'Transmittance.png')

  return filt_tr[:,::-1]
Ejemplo n.º 23
0
def set_defaults():
    """
    Set default plotting behavior.
    """

    start_colors = ["#D11700", "#8EBA42", "#348ABD", "#988ED5", "#777777",
                    "#FBC15E", "#FFB5B8"]
    if LooseVersion(mpl.__version__) < LooseVersion("1.5.1"):
        plt.rcParams["axes.color_cycle"] = start_colors
    else:
        plt.rcParams["axes.prop_cycle"] = plt.cycler("color", start_colors)

    plt.rcParams["axes.facecolor"]  = "w"
    plt.rcParams["axes.grid"]       = True
    plt.rcParams["axes.axisbelow"]  = True
    plt.rcParams["axes.linewidth"]  = 0
    plt.rcParams["axes.labelcolor"] = "k"

    plt.rcParams["figure.facecolor"]      = "w"
    plt.rcParams["figure.subplot.bottom"] = 0.125
    plt.rcParams["figure.subplot.left"]   = 0.1

    plt.rcParams["lines.linewidth"] = 2

    plt.rcParams["grid.color"]     = "#444444"
    plt.rcParams["grid.linewidth"] = 1.5
    plt.rcParams["grid.linestyle"] = ":"

    plt.rcParams["xtick.direction"] = "out"
    plt.rcParams["ytick.direction"] = "out"
    plt.rcParams["xtick.color"]     = "k"
    plt.rcParams["ytick.color"]     = "k"

    plt.rcParams["text.color"] = "k"

    plt.rcParams["image.interpolation"] = "nearest"
    plt.rcParams["image.cmap"] = "gist_gray"

    return
Ejemplo n.º 24
0
 def plot_trend(self, items):
     """
     :param items: list of items we wish to plot  
     :return: plot trending items
     """
     num_plots = len(items)
     plt.gca().set_prop_cycle(
         plt.cycler('color', plt.cm.Accent(np.linspace(0, 1, num_plots))))
     # colormap=plt.cm.gist_ncar
     # plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.9, num_plots)])
     labels = []
     for item in items:
         df_filtered = self.data[self.data['item_id'] == item]
         _lag = df_filtered.lag.tolist()[::-1]
         _num_user = df_filtered.user_count.tolist()[::-1]
         plt.plot(_lag, _num_user)
         labels.append(item)
     plt.legend(labels, ncol=5, loc='upper center')
     plt.title('Top Trending Items')
     plt.ylabel('Number of transactions')
     plt.xlabel('Month-end lag')
     return plt.show()
Ejemplo n.º 25
0
def visualize_dummy_samples(x, y):
    sns.set_style('whitegrid')
    tsne_d = TSNE(init='pca')
    plt.rcParams['axes.prop_cycle'] = plt.cycler(color=[
        "#FF0000", "#005F0E", "#072480", "#55025B", "#FE7878", "#89FA82",
        "#828FFA", "#F38BD8", "#616061"
    ])
    # Dimensionality reduction on the embeddings using t-SNE
    emb_d = tsne_d.fit_transform(x)

    plt.figure(figsize=[10, 7])
    labels = y.cpu().numpy()
    for i in np.unique(labels):
        class_ind = np.where(labels == i)
        plt.scatter(emb_d[class_ind, 0],
                    emb_d[class_ind, 1],
                    label=f'{i}',
                    alpha=0.5,
                    s=5)
        # plt.legend()
    plt.xlabel('t-SNE component 1')
    plt.ylabel('t-SNE component 2')
Ejemplo n.º 26
0
def plot_rewards(simulation_list, list_type="s") -> plt.Figure:
    """
    Plots the cumulative reward of given simulations
    :param simulation_list: list of Simulation objects, whose run_simulation() method was called
    :param list_type str, s for simulation, d for data. s means simulation list contains Simulation objects,
            d means simulation list contains tuples of label,data
    :return: the figure with the plots
    """
    global colormap, fontP
    fontP.set_size('small' if len(simulation_list) > 5 else 'medium')
    fig = plt.figure()
    ax = fig.subplots()
    ax.set_prop_cycle(
        plt.cycler('color', colormap(np.linspace(0, 1, len(simulation_list)))))
    for sim in simulation_list:
        ax.plot(sim.get_reward_sum() if list_type == SIMULATION else sim[1],
                label=sim.type if list_type == SIMULATION else sim[0])
    ax.legend(prop=fontP, framealpha=FRAME_ALPHA)
    ax.set_title("Cumulative Reward")
    ax.set_xlabel(r"Trial")
    ax.set_ylabel(r"Cumulative Reward")
    return fig
def plotBestTeamsWithTupleData(environment_width, environment_height,
                               team_size, runs_to_average, max_steps,
                               min_sensor_radius, max_sensor_radius):
    # Assumes files are spread out across multiple files with distinct data
    test_11_data = []
    for i in range(min_sensor_radius, max_sensor_radius + 1):
        filename = "../../test11_%s_%s_%s_%s_%s_iter%s.p" % (
            environment_width, environment_height, team_size, runs_to_average,
            max_steps, i)
        test_11_data += pickle.load(open(filename, "rb"))

    # Plot Avg Completion Time vs Roomba Ratio
    sensor_radii_to_plot = list(range(min_sensor_radius,
                                      max_sensor_radius + 1))
    plt.gca().set_prop_cycle(
        plt.cycler('color',
                   plt.cm.jet(np.linspace(0, 0.9, len(sensor_radii_to_plot)))))
    for j, sensor_radii in enumerate(sensor_radii_to_plot):
        filtered_data = list(
            filter(lambda tup: tup[0] == sensor_radii, test_11_data))

        # Extract sensor radius, ratio, and completion time
        s = [tup[0] for tup in filtered_data]
        r = [tup[1] for tup in filtered_data]
        c = [np.average(tup[2]) for tup in filtered_data]

        # Annotate the minimum for min/max sensor radius
        if sensor_radii == min_sensor_radius or sensor_radii == max_sensor_radius:
            annot_min(np.array(r), np.array(c))
        plt.plot(r, c)

    legend = ["sensor_radius=" + str(x) for x in sensor_radii_to_plot]
    plt.legend(legend, loc='upper left')
    plt.title(
        'Roomba/Drone Teams of Size %s for varying drone sensor_radius (%sx%s env, average over %s samples each)'
        % (team_size, environment_height, environment_width, runs_to_average))
    plt.xlabel('Ratio of Roomba')
    plt.ylabel('Avg Completion Time')
    plt.show()
Ejemplo n.º 28
0
def _plot(script_runs, min_support_range, show_graph):
    script_names = list(script_runs.keys())
    num_plots = len(script_names)

    color_map = plt.cm.gist_ncar
    plt.gca().set_prop_cycle(plt.cycler('color', plt.cm.jet(np.linspace(0, 1, num_plots))))

    for script_name in script_names:
        plt.plot(range(1, 21), script_runs[script_name])

    plt.legend(script_names)
    plt.ylim(ymin=0)
    # plt.xlim(xmin=0)
    plt.xticks(np.arange(21))
    plt.xlabel('number of bins')
    plt.ylabel('average top 10 lifts')
    grpah_file_name = './img/{}.png'.format(datetime.datetime.now())
    plt.savefig(grpah_file_name)
    print('Graph saved in {}'.format(grpah_file_name))

    if show_graph:
        plt.show()
Ejemplo n.º 29
0
def update_colorcycler(N: int,
                       cmap: str = 'viridis',
                       ax: None or plt.Axes = None):
    """Update color cycler to better automate and choose the colors of certain things

    Parameters
    ----------
    N : int
        Number of colors wanted to cycle through
    cmap : str, optional
        name of the colormap to cycle through, by default 'viridis'
    ax : None or plt.Axes, optional
        Optional Axes to update the color cycler of, by default None

    See Also
    --------
    lwsspy.plot.pick_colors_from_cmap.pick_colors_from_cmap


    Notes
    -----

    :Author:
        Lucas Sawade ([email protected])

    :Last Modified:
        2020.01.13 14.30

    """

    # Get Colors
    colors = lpy.plot.pick_colors_from_cmap(N, cmap=cmap)

    # Set axes
    if ax is None:
        ax = plt.gca()

    # Set axes colorcycler
    ax.set_prop_cycle(plt.cycler('color', colors))
Ejemplo n.º 30
0
def top_states(buffer: io.BytesIO, days: int) -> None:
    plt.rcParams['axes.prop_cycle'] = plt.cycler(color=["#6886c5", "#f1935c", "#a1cae2", "#cd5d7d", "#838383"])

    CSV_TIME_SERIES: str = "https://api.covid19india.org/csv/latest/state_wise_daily.csv"
    df = pd.read_csv(CSV_TIME_SERIES)
    df = df.drop(['Date', 'TT'], axis=1)

    index = pd.date_range(start=df['Date_YMD'][0], end=df['Date_YMD'][len(df) - 1], freq="D")
    index = [pd.to_datetime(date, format='%Y-%m-%d').date() for date in index]

    confirmed = df.iloc[::3, :]
    confirmed.index = index

    if days:
        confirmed = confirmed.tail(days)
    confirmed = confirmed.dropna().drop(['Date_YMD', 'Status'], axis=1)

    s = confirmed.sum().sort_values(ascending=False, inplace=False)
    confirmed = confirmed[s.index[:5]]

    confirmed: pd.DataFrame = confirmed[confirmed.select_dtypes(include=[np.number]).ge(0).all(1)]

    for column in confirmed.columns.values:
        confirmed.rename(columns={column: state_dict[column]}, inplace=True)

    ax = confirmed.dropna().plot(kind='line', linewidth=2.0)

    if not days or (days and days > 100):
        ax.xaxis.set_major_locator(mdates.MonthLocator(interval=1))
        ax.xaxis.set_major_formatter(mdates.DateFormatter('%B %Y'))

    plt.xlabel("Month")
    plt.ylabel("Number of Cases")

    plt.title("COVID-19 India - Top 5 Most Affected States")
    plt.gcf().autofmt_xdate()

    plt.savefig(buffer, format='png', bbox_inches='tight', pad_inches=0.1)
    del [df, confirmed, s]
Ejemplo n.º 31
0
    def plot_observables_allints(self, saveplot=True, odir="./"):
        """
        Plot closure phases and visibility amplitudes vs. baseline length
        for all integrations of an observable set.
        Integrations different colors (really not useful)
        """
        if self.multi:
            t3_bl = self.geometry.t3_bl
            all_cps = self.oi.OI_T3.T3PHI
            vis_bl = self.geometry.vis_bl
            all_visamps = self.oi.OI_VIS.VISAMP
            nints = all_cps.shape[1]
            colormap = plt.cm.gist_ncar
            plt.gca().set_prop_cycle(
                plt.cycler("color", plt.cm.jet(np.linspace(0, 1, nints)))
            )
            fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 7))

            for ii in np.arange(nints):
                ax1.plot(t3_bl, all_cps[:, ii], ".")
                ax2.plot(vis_bl, all_visamps[:, ii], ".")
            ax1.set_xlabel(r"$B_{max}$", size=14)
            ax1.set_ylabel("Closure phase [deg]", size=14)
            ax1.set_title("Closure Phase", size=16)
            ax2.set_title("Visibility Amplitude", size=16)
            ax2.set_xlabel(r"$B_{max}$", size=14)
            ax2.set_ylabel("Visibility Amplitude", size=14)
            plt.suptitle(self.fn)

            if saveplot:
                plotname = os.path.join(odir, self.fn + "_observables_allints.png")
                plt.savefig(plotname)
            else:
                plt.show()
        else:
            print(
                "This is not a multi-integration OIFITS file, use plot_observables function instead."
            )
Ejemplo n.º 32
0
def main(run_id="perf_shift", model_prefix="lenet5"):
    N = 7
    plt.rcParams["axes.prop_cycle"] = plt.cycler(
        "color", plt.cm.viridis(np.linspace(0, 1, N)))
    plt.rcParams.update({'font.size': 14})

    ENABLE_SAVE_FIGURES = True
    RESULTS_DIRECTORY = os.path.relpath(os.path.join(os.getcwd(), 'results'))
    log.info("Results directory: %s", RESULTS_DIRECTORY)
    RUN_ID = run_id

    # set data folders
    res_dir_list = list()
    IMGS_PATH = os.path.join(RESULTS_DIRECTORY, RUN_ID)
    res_dir_list = glob.glob(f"{IMGS_PATH}/{model_prefix}*")
    log.info(f"Result directories: {res_dir_list}")

    # PLOT
    figures = dict()

    # # shifted data
    model_prefix = model_prefix.replace('-', '')
    figures[f"ld-{model_prefix}-rotated.png"] = plot_rotated(res_dir_list)
    figures[f"ld-{model_prefix}-shifted.png"] = plot_shifted(res_dir_list)
    figures[f"ld-{model_prefix}-count60.png"] = plot_confidence_vs_count_60(
        res_dir_list)
    figures[f"ld-{model_prefix}-acc60.png"] = plot_confidence_vs_accuracy_60(
        res_dir_list)

    log.info("cwd: %s", os.getcwd())
    if ENABLE_SAVE_FIGURES:
        log.info("Saving plots")
        # create save folder
        log.info("image path: %s", IMGS_PATH)
        os.makedirs(IMGS_PATH, exist_ok=True)
        # save loop
        for fn in figures:
            figures[fn].savefig(os.path.join(IMGS_PATH, fn), dpi=200)
Ejemplo n.º 33
0
def create_plots(data: List[Tuple[Tuple[List[float], List[int], List[int], List[int]], str]]) -> None:
    colors = ['#2CBDFE', '#47DBCD', '#F3A0F2', '#9D2EC5', '#661D98', '#F5B14C']
    plt.rcParams['axes.prop_cycle'] = plt.cycler(color=colors)

    heap_fig = plt.figure(num='matrace-analyzer (heap usage)')
    stack_fig = plt.figure(num='matrace-analyzer (stack usage)')
    anon_fig = plt.figure(num='matrace-analyzer (anon page usage)')

    heap_axes = heap_fig.gca(title='Heap usage', xlabel='Time (sec)', ylabel='Memory (kilobytes)')
    stack_axes = stack_fig.gca(title='Stack usage', xlabel='Time (sec)', ylabel='Memory (kilobytes)')
    anon_axes = anon_fig.gca(title='Anon page usage', xlabel='Time (sec)', ylabel='Memory (kilobytes)')

    for d in data:
        (time, heap, stack, anon), filename = d
        heap_axes.plot(time, heap, label=filename)
        stack_axes.plot(time, stack, label=filename)
        anon_axes.plot(time, anon, label=filename)

    heap_axes.legend()
    stack_axes.legend()
    anon_axes.legend()

    plt.show()
Ejemplo n.º 34
0
def plot_vol(f_vol, min_history=52):
    """
    plot weekly factor volatilities 
    
    Inputs
    ----------
    f_vol: dataframe
        dataframe containing the weekly factor volatilities
    min_history: int, Default = 52
        minimum number of weeks to calculate volatility

    Outputs
    -------
    None

    """

    plt.figure(figsize=(12, 6))
    plt.gca().set_prop_cycle(
        plt.cycler('color', plt.cm.jet(np.linspace(0, 1, f_vol.shape[1]))))
    plt.plot(100 * f_vol[min_history:])
    plt.legend(f_vol.columns)
    plt.title('Weekly Factor Volatilities (%)')
Ejemplo n.º 35
0
def plot_map_by_number(angles, show=True, argsort=False):
    cm = plt.cm.viridis
    plt.gca().set_prop_cycle(
        plt.cycler('color', cm(np.linspace(0, 1, len(angles)))))
    for i, solution in tq.tqdm(enumerate(angles)):
        t = solution.t
        results = solution.y.T
        mod_θ2 = centre_plane(results[:, 0])
        x_points = find_crossing_points(mod_θ2)
        ϕ1s = []
        ϕ2s = []
        θ2s = []
        for x in x_points:
            if x[0] <= 1: continue
            f1, f2, f3, f4 = interpolate_functions(x[0], t, results)
            t0 = find_zero(x[0], t, f1)
            ϕ1_0 = f2(t0)
            ϕ2_0 = f3(t0)
            θ2_0 = f4(t0)

            ϕ1s.append(ϕ1_0)
            ϕ2s.append(ϕ2_0)
            θ2s.append(θ2_0)

        if argsort:
            phi1_index = np.mod(np.array(ϕ1s), 2 * np.pi).argsort()
            plt.plot(np.mod(np.array(ϕ1s)[phi1_index], np.pi * 2),
                     np.mod(np.array(θ2s)[phi1_index], np.pi * 2),
                     ms=0.5,
                     marker='o')
        else:
            plt.scatter(np.mod(np.array(ϕ1s), np.pi * 2),
                        np.mod(np.array(θ2s), np.pi * 2),
                        s=0.5)
    if show:
        plt.colorbar()
        plt.show()
Ejemplo n.º 36
0
Archivo: covid.py Proyecto: obviyus/bot
def total(buffer: io.BytesIO, days: int) -> None:
    plt.rcParams['axes.prop_cycle'] = plt.cycler(
        color=['#ea5455', '#1fab89', '#b19cd9'])

    CSV_TIME_SERIES: str = "https://api.covid19india.org/csv/latest/case_time_series.csv"
    df = pd.read_csv(CSV_TIME_SERIES)

    df = df.drop(
        ['Total Confirmed', 'Total Recovered', 'Total Deceased', 'Date'],
        axis=1,
        errors='ignore')

    index = pd.date_range(start=df['Date_YMD'][0],
                          end=df['Date_YMD'][len(df) - 1],
                          freq="D")
    index = [pd.to_datetime(date, format='%Y-%m-%d').date() for date in index]
    df.index = index

    if days:
        df = df.tail(days)

    df = df.drop('Date_YMD', axis=1)
    ax = df.plot(y=['Daily Confirmed', 'Daily Recovered', 'Daily Deceased'],
                 kind='line',
                 linewidth=2.0)

    if not days or (days and days > 100):
        ax.xaxis.set_major_locator(mdates.MonthLocator(interval=1))
        ax.xaxis.set_major_formatter(mdates.DateFormatter('%B %Y'))
    plt.gcf().autofmt_xdate()

    plt.xlabel("Month")
    plt.ylabel("Number of Cases")
    plt.title("COVID-19 India")

    plt.savefig(buffer, format='png', pad_inches=0.1, bbox_inches='tight')
    del df
def ql_errors(ql_data, out, name):
    fig, ax = plt.subplots(figsize=(10, 5))
    s = config['ql_params'][name]['S']
    colormap = plt.cm.gist_ncar

    markers = itertools.cycle((',', '+', 'x', 'o', '*', 's', 'd'))
    num_plots = len(config['ql_alpha']) * len(config['ql_epsilon']) + 2
    plt.gca().set_prop_cycle(
        plt.cycler('color', plt.cm.jet(np.linspace(0, 3, num_plots))))

    for eps, alpha in list(
            ql_data[['epsilon',
                     'alpha']].drop_duplicates().to_records(index=False)):
        #print(alpha, eps)
        x = ql_data[(ql_data['epsilon'] == eps)
                    & (ql_data['alpha'] == alpha)][[
                        'error_mean', 'mean_V', 'reward', 'policy'
                    ]]

        #plt.plot(x['error_mean'].values[0], label='Error alpha='+str(alpha)+' eps='+str(eps), alpha=0.5)
        plt.plot(x['error_mean'].values[0],
                 marker=next(markers),
                 markersize='5',
                 markevery=100,
                 alpha=0.5,
                 label='alpha=' + str(round(alpha, 3)) + ' eps=' +
                 str(round(eps, 3)))
        #plt.plot(x['reward'].values[0], label='Reward V alpha='+str(alpha)+' eps='+str(eps), alpha=0.25)
    #plt.xscale('log')
    plt.grid(which='both')
    plt.xlabel('iterations/' + str(config['ql_iters'][0] // 10000))
    plt.ylabel('error')
    plt.legend(prop={'size': 7})
    plt.title('QL Error-' + name.upper())
    plt.tight_layout()
    plt.savefig(os.path.join(out, 'ql_error-' + name.upper() + '.png'))
    plt.close()
Ejemplo n.º 38
0
def plotCNo(satellites):
    fig, ax = plt.subplots(figsize=(18 ,15))
    timestamps = list(satellites.keys())
    x = range(len(timestamps))
    SatIDs = satellites.values()
    tmp = []

    for sats in SatIDs:
        for sat in sats:
            if int(sat) not in tmp:
                tmp.append(int(sat))
    tmp.sort()

    ax.set_prop_cycle(plt.cycler("color", plt.cm.hsv(np.linspace(0,1,len(tmp)))))
    for count, sv in enumerate(tmp):
        y = []
        for sats in SatIDs:
            for sat in sats:
                if str(sv) in sats:
                    if sat == str(sv):
                        try:
                            y.append(float(sats[sat][0]))
                        except ValueError:
                            y.append(0)
                        break
                else:
                    y.append(0)
                    break
        ax.plot(x, y, label=sv)
    plot_title = title + " Carrier noise ratio of Satellites in view"
    ax.set(xlabel = 'Time (s)', ylabel = 'C/No (dB/Hz)', title = plot_title)
    ax.set_ylim(ymin=0)
    ax.set_xlim(xmin=0)
    ax.legend(title="Satellite ID", loc='lower right', shadow=True, ncol=2)
    fig.savefig(("../Images/" + datetitle + " Carrier noise ratio.png"), bbox_inches='tight')
    plt.tight_layout()
    plt.show()
Ejemplo n.º 39
0
print(stats.describe(mt_defaul_list))

colors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00']

params = {'figure.facecolor': 'white',
          'figure.subplot.bottom': 0.0,
          'font.size': 16,
          'legend.fontsize': 16,
          'legend.borderpad': 0.2,
          'legend.labelspacing': 0.2,
          'legend.handlelength': 1.5,
          'legend.handletextpad': 0.4,
          'legend.borderaxespad': 0.2,
          'lines.markeredgewidth': 2.0,
          'lines.linewidth': 2.0,
          'axes.prop_cycle': plt.cycler('color', colors)}
plt.rcParams.update(params)


fig, ax = plt.subplots(3)
ax[0].hist(predictions, 50, range=(0.0, 400.0), label='Pred', histtype='step')
ax[0].hist(target, 50, range=(0.0, 400.0), label='Truth', histtype='step')
ax[0].set_xlim([0, 400])
ax[0].set_xlabel("pT (GeV)")
ax[0].legend(loc='upper right')
ax[1].hist(result_predict, 50, range=(-100.0, 100.0), label='Pred', histtype='step')
ax[1].hist(result_default, 50, range=(-100.0, 100.0), label='Default', histtype='step')
ax[1].hist(met_truth_list, 50, range=(-100.0, 100.0), label='truth_met - met/truth_met', histtype='step')
ax[1].set_xlim([-100, 100])
ax[1].set_xlabel("Resolution (%)")
ax[1].legend(loc='upper left')
Ejemplo n.º 40
0
def run(job_list, output_dir):
    print("Running time_series.py")
    plt.style.use('fivethirtyeight')
    plt.rcParams['lines.linewidth'] = 0
    plt.rcParams['patch.linewidth'] = 0
    plt.rcParams['axes.prop_cycle'] = plt.cycler('color', sfbi_utils.get_colors())
    # disable silly warning
    pd.options.mode.chained_assignment = None

    df = pd.DataFrame(job_list, columns=['_id', 'city', 'user', 'submission_date', 'contract_type', 'contract_subtype'])

    df2 = pd.DataFrame({'date': df.submission_date, 'type': df.contract_type})
    df2_g = pd.DataFrame({'count': df2.groupby(['type', 'date']).size()}).reset_index()
    df2_t = df2_g.pivot(index='date', columns='type', values='count')
    df2_t.index = pd.to_datetime(df2_t.index)
    df2_t2 = df2_t.resample('1M').sum()
    df2_t2.columns.name = 'Type'
    ax = df2_t2.plot(kind='area')
    plt.title(u'Évolution des types de poste', y=1.08)
    ax.set_xlabel('Date')
    ax.set_ylabel("Nombre d'offres")
    plt.savefig(os.path.join(output_dir, 'time_series_1.svg'), bbox_inches='tight')
    plt.close()

    # just CDD
    df3 = pd.DataFrame({'date': df.submission_date, 'subtype': df.contract_subtype})
    df3_g = pd.DataFrame({'count': df3.groupby(['subtype', 'date']).size()}).reset_index()
    tmp = df3_g['subtype'].isin(['Post-doc / IR', u'CDD Ingénieur', 'CDD autre', 'ATER'])
    df3_g = df3_g[tmp].reset_index()
    df3_t = df3_g.pivot(index='date', columns='subtype', values='count')
    df3_t.index = pd.to_datetime(df3_t.index)
    df3_t2 = df3_t.resample('1M').sum()
    df3_t2.columns.name = 'Type'
    ax = df3_t2.plot(kind='area')
    plt.title(u'Évolution des types de CDD', y=1.08)
    ax.set_xlabel('Date')
    ax.set_ylabel("Nombre d'offres")
    plt.savefig(os.path.join(output_dir, 'time_series_2.svg'), bbox_inches='tight')
    plt.close()

    # just CDI
    df3 = pd.DataFrame({'date': df.submission_date, 'subtype': df.contract_subtype})
    df3_g = pd.DataFrame({'count': df3.groupby(['subtype', 'date']).size()}).reset_index()
    tmp = df3_g['subtype'].isin(['CDI autre', 'IE', 'IR', 'PR', 'MdC', 'CR'])
    df3_g = df3_g[tmp]
    df3_t = df3_g.pivot(index='date', columns='subtype', values='count')
    df3_t.index = pd.to_datetime(df3_t.index)
    df3_t2 = df3_t.resample('1M').sum()
    df3_t2.columns.name = 'Type'
    ax = df3_t2.plot(kind='area')
    plt.title(u'Évolution des types de CDI', y=1.08)
    ax.set_xlabel('Date')
    ax.set_ylabel("Nombre d'offres")
    plt.savefig(os.path.join(output_dir, 'time_series_3.svg'), bbox_inches='tight')
    plt.close()

    df4 = pd.DataFrame({'date': pd.to_datetime(df.submission_date)})
    df4_g = pd.DataFrame({'count': df4.groupby('date').size()})
    df4_t = df4_g.resample('1M').sum()
    plt.figure()
    ax = df4_t.plot(linewidth=4)
    plt.title(u"Évolution du nombre total d'offre", y=1.08)
    ax.set_xlabel('Date')
    ax.set_ylabel("Nombre d'offres")
    plt.savefig(os.path.join(output_dir, 'time_series_4.svg'), bbox_inches='tight')
    plt.close()

    '''
        contract type proportions
    '''
    # get the interesting fields and count the type for each date
    df5 = pd.DataFrame({'date': df.submission_date, 'type': df.contract_type})
    df5_g = pd.DataFrame({'count': df5.groupby(['type', 'date']).size()}).reset_index()
    # have all the types as column and each date as one line
    df5_t = df5_g.pivot(index='date', columns='type', values='count')
    df5_t.index = pd.to_datetime(df5_t.index)
    # make it per month
    df5_t2 = df5_t.resample('1M').sum().fillna(0)
    # add a total column to compute ratio
    df5_t2['total'] = df5_t2.CDD + df5_t2.CDI + df5_t2.Stage + df5_t2[u'Thèse']
    # replace all the values by ratios
    df5_t3 = pd.DataFrame(df5_t2).apply(lambda x: (x / x['total'] * 100), axis=1).fillna(0).drop('total', 1)
    df5_t3.columns.name = 'Type'
    proportion_stackplot(df5_t3, output=os.path.join(output_dir, 'time_series_5.svg'), xlabel='Date',
                         ylabel='%des offres',
                         title=u"Évolution de la proportion des types de poste")

    '''
        contract subtype proportions for CDI
    '''
    # get the interesting fields only for CDI
    df6 = pd.DataFrame({'date': df.submission_date, 'subtype': df.contract_subtype})[df['contract_type'] == 'CDI']
    df6_g = pd.DataFrame({'count': df6.groupby(['subtype', 'date']).size()}).reset_index()
    # have all the types as column and each date as one line
    df6_t = df6_g.pivot(index='date', columns='subtype', values='count')
    df6_t.index = pd.to_datetime(df6_t.index)
    # make it per month
    df6_t2 = df6_t.resample('1M').sum().fillna(0)
    # add a total column to compute ratio
    df6_t2['total'] = df6_t2['CDI autre'] + df6_t2.CR + df6_t2.IE + df6_t2.IR + df6_t2.MdC + df6_t2.PR
    # replace all the values by ratios
    df6_t3 = pd.DataFrame(df6_t2).apply(lambda x: (x / x['total'] * 100), axis=1).fillna(0).drop('total', 1)
    df6_t3.columns.name = 'Type'
    proportion_stackplot(df6_t3, output=os.path.join(output_dir, 'time_series_6.svg'), xlabel='Date',
                         ylabel='%des offres',
                         title=u"Évolution de la proportion des types de CDI")

    '''
        contract subtype proportions for CDD
    '''
    # get the interesting fields only for CDD
    df7 = pd.DataFrame({'date': df.submission_date, 'subtype': df.contract_subtype})[df['contract_type'] == 'CDD']
    # count subtype for each date
    df7_g = pd.DataFrame({'count': df7.groupby(['subtype', 'date']).size()}).reset_index()
    # have all the types as column and each date as one line
    df7_t = df7_g.pivot(index='date', columns='subtype', values='count')
    df7_t.index = pd.to_datetime(df7_t.index)
    # make it per month
    df7_t2 = df7_t.resample('1M').sum().fillna(0)
    # add a total column to compute ratio
    df7_t2['total'] = df7_t2.ATER + df7_t2[u'CDD Ingénieur'] + df7_t2['CDD autre'] + df7_t2['Post-doc / IR']
    # replace all the values by ratios
    df7_t3 = pd.DataFrame(df7_t2).apply(lambda x: (x / x['total'] * 100), axis=1).fillna(0).drop('total', 1)
    df7_t3.columns.name = 'Type'
    proportion_stackplot(df7_t3, output=os.path.join(output_dir, 'time_series_7.svg'), xlabel='Date',
                         ylabel='%des offres',
                         title=u'Évolution de la proportion des types de CDD')

    # education level quantity
    df8 = pd.DataFrame({'date': df.submission_date, 'type': df.contract_subtype})
    df_bool_master = df8['type'].isin([u'CDD Ingénieur', 'IE'])
    df_bool_phd = df8['type'].isin(['Post-doc / IR', 'PR', 'MdC', 'CR', 'IR', 'ATER'])
    df_master = df8[df_bool_master]
    df_master['type'] = 'Master'
    df_phd = df8[df_bool_phd]
    df_phd['type'] = 'PhD'
    df8 = pd.DataFrame({'count': pd.concat([df_phd, df_master]).groupby(['type', 'date']).size()}).reset_index()
    df8_t = df8.pivot(index='date', columns='type', values='count')
    df8_t.index = pd.to_datetime(df8_t.index)
    df8_t2 = df8_t.resample('1M').sum().fillna(0)
    df8_t2.columns.name = 'Niveau'
    ax = df8_t2.plot(kind='area')
    ax.set_xlabel('Date')
    ax.set_ylabel("Nombre d'offres")
    plt.title(u"Nombre de CDD et CDI en fonction du niveau de diplôme", y=1.08)
    plt.savefig(os.path.join(output_dir, 'time_series_8.svg'), bbox_inches='tight')
    plt.close()

    '''
        education level proportions
    '''
    # add a total column to compute ratio
    df9 = df8_t2
    df9['total'] = df9.Master + df9.PhD
    # replace all the values by ratios
    df9 = pd.DataFrame(df9).apply(lambda x: (x / x['total'] * 100), axis=1).fillna(0).drop('total', 1)
    proportion_stackplot(df9, output=os.path.join(output_dir, 'time_series_9.svg'), xlabel='Date', ylabel='%des offres',
                         title=u'Proportion des niveaux de diplôme requis pour les CDD et CDI')

    '''
       average year series
    '''
    df10 = pd.DataFrame({'date': df.submission_date,
                         'type': df.contract_type})  # .reset_index().groupby(['date'])['index'].count().reset_index(name='count')
    df10 = df10.set_index(pd.DatetimeIndex(df10['date']))
    df10['month'] = df10.index.month
    df10 = (df10['2013':'2016'].groupby(['month', 'type'])['month'].count() / 4).reset_index(name='count')
    df10_t = df10.pivot(index='month', columns='type', values='count').fillna(0)
    df10_t.columns.name = 'Type'
    ax = df10_t.plot(linewidth=4)
    ax.set_xlabel('Mois')
    ax.set_ylabel("Nombre d'offres")
    plt.title(u'Moyennes mensuelles 2013-2016', y=1.08)
    ax.legend(loc='center right', bbox_to_anchor=(1.25, 0.5))
    plt.savefig(os.path.join(output_dir, 'time_series_10.svg'), bbox_inches='tight')
    plt.close()

    CDD_subtypes = ['Post-doc / IR', u'CDD Ingénieur', 'CDD autre', 'ATER']
    df11 = pd.DataFrame({'date': df.submission_date, 'type': df.contract_subtype})
    tmp = df11['type'].isin(CDD_subtypes)
    df11 = df11[tmp]
    df11 = df11.set_index(pd.DatetimeIndex(df11['date']))
    df11['month'] = df11.index.month
    df11 = (df11['2013':'2016'].groupby(['month', 'type'])['month'].count() / 4).reset_index(name='count')
    df11_t = df11.pivot(index='month', columns='type', values='count').fillna(0)
    df11_t.columns.name = 'Type'
    ax = df11_t.plot(linewidth=4)
    ax.set_xlabel('Mois')
    ax.set_ylabel("Nombre d'offres")
    plt.title(u'Moyennes mensuelles 2013-2016 pour les CDD', y=1.08)
    ax.legend(loc='center right', bbox_to_anchor=(1.4, 0.5))
    plt.savefig(os.path.join(output_dir, 'time_series_11.svg'), bbox_inches='tight')
    plt.close()

    CDI_subtypes = ['CDI autre', 'IE', 'IR', 'PR', 'MdC', 'CR']
    df12 = pd.DataFrame({'date': df.submission_date, 'type': df.contract_subtype})
    tmp = df12['type'].isin(CDI_subtypes)
    df12 = df12[tmp]
    df12 = df12.set_index(pd.DatetimeIndex(df12['date']))
    df12['month'] = df12.index.month
    df12 = (df12['2013':'2016'].groupby(['month', 'type'])['month'].count() / 4).reset_index(name='count')
    df12_t = df12.pivot(index='month', columns='type', values='count').fillna(0)
    df12_t.columns.name = 'Type'
    ax = df12_t.plot(linewidth=4)
    plt.legend(loc=7)
    ax.set_xlabel('Mois')
    ax.set_ylabel("Nombre d'offres")
    plt.title(u'Moyennes mensuelles 2013-2016 pour les CDI', y=1.08)
    ax.legend(loc='center right', bbox_to_anchor=(1.3, 0.5))
    plt.savefig(os.path.join(output_dir, 'time_series_12.svg'), bbox_inches='tight')
    plt.close()
Ejemplo n.º 41
0
def plotSSCurve(sensitivity, specificity, people=[], title="", show_legend=False, textcolor='#4D5B66', plot_results=True):
    """SS curve for Publications.

    Args:
        sensitivity (numpy.array): length-N array of sensitivity points.
        specificity (numpy.array): length-N array of specificity points.
        people (list): List of lists. Each list entry is two float values:
            [persons_sensitivity, persons_specificity]

    Returns
        the handle to the figure, for further plotting.
    """
    area = auc(sensitivity, specificity)
    print 'The AUC is %s' % area

#   textcolor = 'black'
#   textcolor = 'darkgrey'
#   textcolor = '#4D5B66'
    textsize = 24
    rcParams = {
            'axes.grid' : False,
            'font.family' : 'sans-serif',
            'text.color' : textcolor,
            'axes.labelcolor' : textcolor,
            'axes.labelsize' : textsize,
            'axes.titlesize' : textsize,
            'axes.facecolor' : 'white',
            'axes.linewidth' : 3,
            'axes.prop_cycle' : plt.cycler('color', ['blue', 'black', '#5BC0DE', 'blue']),
            'figure.figsize' : (8,8),
            'xtick.color' : textcolor,
            'xtick.labelsize' : 20,
            'xtick.major.pad' : 15,
            'ytick.color' : textcolor,
            'ytick.labelsize' : 20,
            'ytick.major.pad' : 15,
            'legend.fontsize' : 20,
            }
    with plt.rc_context(rcParams):
        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.spines['top'].set_visible(False)
        ax.spines['right'].set_visible(False)
        plt.plot(sensitivity, specificity, label='Algorithm: AUC=%0.2f' % area, linewidth=4)
        xlabel = 'Sensitivity'
        ylabel = 'Specificity'
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        plt.ylim([0.0, 1.05])
        plt.xlim([0.0, 1.05])
        plt.yticks([0.0, 1.0], ["0", "1"])
        plt.xticks([0.0, 1.0], ["0", "1"])
        plt.axhline(y=1.0, xmin=0, xmax=0.95, color='k', zorder=-34, ls='dashed')
        plt.axhline(y=0.9, xmin=0, xmax=0.95, color='k', zorder=-34, ls='dashed')
        plt.axhline(y=0.8, xmin=0, xmax=0.95, color='k', zorder=-34, ls='dashed')
        plt.axvline(x=1.0, ymin=0, ymax=0.95, color='k', zorder=-34, ls='dashed')
        plt.axvline(x=0.9, ymin=0, ymax=0.95, color='k', zorder=-34, ls='dashed')
        plt.axvline(x=0.8, ymin=0, ymax=0.95, color='k', zorder=-34, ls='dashed')
        area = "%0.2f" % area
        title = title  + '\n'
        plt.title(title)
        for i, person in enumerate(people):
            if i == 0:
                plt.plot(person[0], person[1], 'o', color='red', zorder=-32, markersize=10, label='Dermatologists (%d)' % len(people))
            else:
                plt.plot(person[0], person[1], 'o', color='red', zorder=-32, markersize=10)
        if len(people) > 0:
            avg_sensitivity = np.mean(np.array(people)[:,0])
            avg_specificity = np.mean(np.array(people)[:,1])
            std_sensitivity = np.std(np.array(people)[:,0])
            std_specificity = np.std(np.array(people)[:,1])
            print 'Average sensitivity=%0.2f +- %0.2f' % (avg_sensitivity, std_sensitivity)
            print 'Average specificity=%0.2f +- %0.2f' % (avg_specificity, std_specificity)
            plt.plot(avg_sensitivity, avg_specificity, 'D', color='green', markersize=10, label='Average Dermatologist')
            plt.errorbar(avg_sensitivity, avg_specificity, xerr=std_sensitivity, yerr=std_specificity,
                    color='green', markersize=10, elinewidth=3)

        if show_legend:
            plt.legend(loc='lower left', numpoints= 1)
        if plot_results:
            plt.show()
    return fig, ax
Ejemplo n.º 42
0
def plot_species(df, species_list=None, save_name='test', out_dir=None,
                 title=None, plot_type='plotly', image_format='pdf',
                 close_plots=False):
    """

    Parameters
    ----------
    df: pandas.DataFrame
        magine formatted dataframe
    species_list: list
        List of genes to be plotter
    save_name: str
        Filename to be saved as
    out_dir: str
        Path for output to be saved
    title: str
        Title of plot, useful when list of genes corresponds to a GO term
    plot_type : str
        Use plotly to generate html output or matplotlib to generate pdf
    image_format : str
        pdf or png, only used if plot_type="matplotlib"
    close_plots : bool
        Close plot after making, use when creating lots of plots in parallel.
    Returns
    -------

    """

    ldf = df.copy()

    if out_dir is not None:
        if not os.path.exists(out_dir):
            os.mkdir(out_dir)

    # gather x axis points
    x_points = sorted(ldf[sample_id].unique())
    if len(x_points) == 0:
        return
    if isinstance(x_points[0], np.float):
        x_point_dict = {i: x_points[n] for n, i
                        in enumerate(x_points)}
    else:
        x_point_dict = {i: n for n, i
                        in enumerate(x_points)}
    if species_list is not None:
        ldf = ldf.loc[ldf[identifier].isin(species_list)].copy()

    ldf = log2_normalize_df(ldf, column=fold_change)

    n_plots = len(ldf[identifier].unique())
    num_colors = len(ldf[label_col].unique())
    color_list = sns.color_palette("tab20", num_colors)
    if plot_type == 'matplotlib':
        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.set_prop_cycle(plt.cycler('color', color_list))

    colors = enumerate(color_list)

    plotly = []
    names_list = []
    total_counter = 0
    for name, j in ldf.groupby(identifier):
        index_counter = 0
        for n, m in j.groupby(label_col):

            x = np.array(m[sample_id])
            if len(x) < 1:
                continue
            y = np.array(m['fold_change'])
            sig_flag = np.array(m[flag])
            index = np.argsort(x)
            x = x[index]
            y = y[index]
            s_flag = sig_flag[index]

            # x values with scaled values (only changes things if non-float
            # values are used for sample_id
            x_index = np.array([x_point_dict[ind] for ind in x])

            index_counter += 1
            total_counter += 1

            # create matplotlib plot
            if plot_type == 'matplotlib':
                label = "\n".join(wrap(n, 40))
                p = ax.plot(x_index, y, '.-', label=label)
                if len(s_flag) != 0:
                    color = p[0].get_color()
                    ax.plot(x_index[s_flag], y[s_flag], '^', color=color)

            # create plotly plot
            elif plot_type == 'plotly':
                c = next(colors)[1]
                plotly.append(_ploty_graph(x_index, y, n, n, c))
                if len(s_flag) != 0:
                    index_counter += 1
                    total_counter += 1
                    plotly.append(_ploty_graph(x_index[s_flag], y[s_flag],
                                               n, n, c, marker='x-open-dot'))
        names_list.append([name, index_counter])
    if plot_type == 'matplotlib':
        lgd = _format_mpl(ax, x_point_dict, x_points)
        if save_name is not None:
            tmp_savename = "{}.{}".format(save_name, image_format)
            if out_dir is not None:
                tmp_savename = os.path.join(out_dir, tmp_savename)
            plt.savefig(tmp_savename, bbox_extra_artists=(lgd,),
                        bbox_inches='tight')

        if close_plots:
            plt.close(fig)
        else:
            return fig

    elif plot_type == 'plotly':
        fig = _create_plotly(total_counter, n_plots, names_list, x_point_dict,
                             title, x_points, plotly)
        if save_name:
            _save_ploty_output(fig, out_dir, save_name)
        else:
            init_notebook_mode(connected=True)
            iplot(fig)
Ejemplo n.º 43
0
def run(job_list, output_dir):
    print("Running summary.py")
    contract_subtype_level = {'Post-doc / IR': 'PhD',
                              'PR': 'PhD',
                              'MdC': 'PhD',
                              'CR': 'PhD',
                              'IR': 'PhD',
                              'ATER': 'PhD',
                              u'CDD Ingénieur': 'Master',
                              'IE': 'Master'}
    colors = sfbi_utils.get_colors()

    plt.style.use('fivethirtyeight')
    plt.rcParams['axes.prop_cycle'] = plt.cycler('color', sfbi_utils.get_colors())
    # for the pie charts
    plt.rcParams['patch.linewidth'] = 1
    plt.rcParams['patch.edgecolor'] = 'white'

    df = pd.DataFrame(job_list, columns=['_id', 'contract_type', 'contract_subtype', 'city', 'submission_date'])

    summary_file = open(os.path.join(output_dir, 'summary.txt'), 'w')
    submission_date_series = pd.Series(df.submission_date)
    summary_file.write("From " + str(submission_date_series.min()) + " to " + str(submission_date_series.max()) + '\n')
    summary_file.write("Total jobs: " + str(len(df.index)) + "\n")
    summary_file.write(pd.Series(df.contract_type).value_counts().to_string(header=False) + "\n")

    # general types ratios pie chart
    df_contract_type_count = pd.Series(df.contract_type).value_counts(sort=True)
    fig, ax = minimal_hbar(df_contract_type_count)
    ax.set_title(u'Types de postes')
    fig.savefig(os.path.join(output_dir, 'summary_6.svg'), bbox_inches='tight')
    plt.close(fig)

    plt.figure()
    ax = df_contract_type_count.plot(kind='pie', startangle=90, autopct='%1.1f%%', colors=colors)
    ax.set_xlabel('')
    ax.set_ylabel('')
    plt.axis('equal')
    plt.title('Types de poste', y=1.08)
    plt.savefig(os.path.join(output_dir, 'summary_1.svg'), bbox_inches='tight')
    plt.close()

    # CDI subtypes ratios pie chart
    df_contract_subtype_CDI_count = pd.Series(df[df.contract_type == 'CDI'].contract_subtype).value_counts(sort=True)
    fig, ax = minimal_hbar(df_contract_subtype_CDI_count)
    ax.set_title(u'Types de CDI')
    fig.savefig(os.path.join(output_dir, 'summary_7.svg'), bbox_inches='tight')
    plt.close(fig)

    plt.figure()
    ax = df_contract_subtype_CDI_count.plot(kind='pie', startangle=90, autopct='%1.1f%%', colors=colors)
    ax.set_xlabel('')
    ax.set_ylabel('')
    plt.axis('equal')
    plt.title('Types de CDI', y=1.08)
    plt.savefig(os.path.join(output_dir, 'summary_2.svg'), bbox_inches='tight')
    plt.close()

    # CDD subtypes ratios pie chart
    df_contract_subtype_CDD_count = pd.Series(df[df.contract_type == 'CDD'].contract_subtype).value_counts(sort=True)
    fig, ax = minimal_hbar(df_contract_subtype_CDD_count)
    ax.set_title(u'Types de CDD')
    fig.savefig(os.path.join(output_dir, 'summary_8.svg'), bbox_inches='tight')
    plt.close(fig)

    plt.figure()
    ax = df_contract_subtype_CDD_count.plot(kind='pie', startangle=90, autopct='%1.1f%%', colors=colors)
    ax.set_xlabel('')
    ax.set_ylabel('')
    plt.axis('equal')
    plt.title('Types de CDD', y=1.08)
    plt.savefig(os.path.join(output_dir, 'summary_3.svg'), bbox_inches='tight')
    plt.close()

    # best cities
    df_city = pd.Series(df.city).value_counts()
    # df_city = df_city[df_city >= 10]
    sum_small_cities = df_city.iloc[16:].sum()
    df_city = df_city.iloc[:15]
    df_city['Autres'] = sum_small_cities
    # plt.figure()
    city_names = df_city.index
    labels = ['{0} - {1:1.2f} %'.format(i, j) for i, j in zip(city_names, 100. * df_city / df_city.sum())]
    # [' '] * len(labels) -> empty labels for each pie, to avoid matplotlib warning
    axes = pd.DataFrame(df_city).plot(kind='pie', startangle=90, labels=[' '] * len(labels), colors=colors,
                                      subplots=True)
    for ax in axes:
        ax.legend(labels, loc=1, bbox_to_anchor=(1.5, 1.1))
        ax.set_xlabel('')
        ax.set_ylabel('')
    plt.axis('equal')
    plt.title("Parts des 15 villes ayant le plus d'offres d'emploi", y=1.08)
    plt.savefig(os.path.join(output_dir, 'summary_4.svg'), bbox_inches='tight')
    plt.close()

    # education level ratios pie chart
    df_study_level = pd.Series(df.contract_subtype).value_counts(sort=True)
    level_dict = {'PhD': 0, 'Master': 0}
    for subtype in df_study_level.index:
        if subtype in contract_subtype_level:
            level = contract_subtype_level[subtype]
            level_dict[level] += df_study_level[subtype]
    plt.figure()
    ax = pd.Series(level_dict).plot(kind='pie', startangle=90, autopct='%1.1f%%', colors=colors)
    ax.set_xlabel('')
    ax.set_ylabel('')
    plt.axis('equal')
    plt.title(u'Niveau de diplôme requis pour les CDD et CDI', y=1.08)
    plt.savefig(os.path.join(output_dir, 'summary_5.svg'), bbox_inches='tight')
    plt.close()

    # per city contract types
    city_gb = df.groupby('city')
    df_type_city = city_gb.contract_type.value_counts(sort=True, ascending=True).unstack(level=-1).fillna(0)
    df_type_city['Total'] = df_type_city.sum(axis='columns')
    df_perc_city = df_type_city.div(df_type_city['Total'], axis='index')
    df_perc_city['Total'] = df_type_city['Total']
    df_perc_city = df_perc_city.sort_values(by='Total')
    fig, ax = plt.subplots()
    ax = df_perc_city.loc[:, ['CDD', 'CDI', 'Stage', u'Thèse']].iloc[-10:].plot(ax=ax, kind='barh', stacked=True,
                                                                                color=colors)
    ax.set_xlim([0, 1])
    ax.set_ylabel('')
    i = 0
    for total in df_perc_city['Total'].iloc[-10:]:
        ax.text(1.02, i, int(total), va='center')
        i += 1
    plt.title(u"Répartition des types d'offres\ndans les 10 villes ayant le plus d'offres", y=1.08)
    ax.legend(loc='lower center', bbox_to_anchor=(0.5, -0.2), ncol=4)
    fig.savefig(os.path.join(output_dir, 'summary_9.svg'), bbox_inches='tight')
    plt.close(fig)

    # per city education level
    def get_jobs_educ_level(series):
        level_dict = {'PhD': 0, 'Master': 0}
        for e in series.index:
            if e in contract_subtype_level:
                level_dict[contract_subtype_level[e]] += series[e]
        return pd.Series(level_dict)

    def count_master(series):
        return get_jobs_educ_level(series.value_counts())['Master']

    def count_phd(series):
        return get_jobs_educ_level(series.value_counts())['PhD']

    df_level_city = city_gb.contract_subtype.aggregate({'Master': count_master, 'PhD': count_phd})
    df_level_city['Total'] = df_level_city['Master'] + df_level_city['PhD']
    df_level_perc = df_level_city.div(df_level_city['Total'], axis='index')
    df_level_perc['Total'] = df_level_city['Total']
    df_level_perc = df_level_perc.sort_values(by='Total')
    fig, ax = plt.subplots()
    ax = df_level_perc.loc[:, ['Master', 'PhD']].iloc[-10:].plot(ax=ax, kind='barh', stacked=True, color=colors)
    ax.set_xlim([0, 1])
    ax.set_ylabel('')
    i = 0
    for total in df_level_perc['Total'].iloc[-10:]:
        ax.text(1.02, i, int(total), va='center')
        i += 1
    plt.title(u"Proportion des niveaux de diplôme requis\ndans les 10 villes ayant le plus d'offres", y=1.08)
    ax.legend(loc='lower center', bbox_to_anchor=(0.5, -0.2), ncol=4)
    fig.savefig(os.path.join(output_dir, 'summary_10.svg'), bbox_inches='tight')
    plt.close(fig)
Ejemplo n.º 44
0
############################################################################
# Calculation with Berreman4x4
data = Berreman4x4.DataList([s.evaluate(kx,k0) for kx in Kx])

R_p = data.get('R_pp')
R_s = data.get('R_ss')
T_p = data.get('T_pp')
T_s = data.get('T_ss')
t2_p = abs(data.get('t_pp'))**2  # Before power correction
t2_s = abs(data.get('t_ss'))**2

############################################################################
# Plotting
fig = pyplot.figure(figsize=(12., 6.))
pyplot.rcParams['axes.prop_cycle'] = pyplot.cycler('color', 'bgrcbg')
ax = fig.add_axes([0.1, 0.1, 0.7, 0.8])

y = numpy.vstack((R_s,R_p,t2_s,t2_p,T_s,T_p)).T
legend1 = ("R_s","R_p","t2_s","t2_p","T_s","T_p")
lines1 = ax.plot(Kx, y)

y_th = numpy.vstack((R_th_s, R_th_p, t2_th_s, t2_th_p,
                  T_th_s, T_th_p)).T
legend2 = ("R_th_s", "R_th_p", "t2_th_s", "t2_th_p",
           "T_th_s", "T_th_p")
lines2 = ax.plot(Kx, y_th, 'x')

ax.legend(lines1 + lines2, legend1 + legend2, 
          loc='upper left', bbox_to_anchor=(1.05, 1), borderaxespad=0.)
Ejemplo n.º 45
0
                         lumi_par_tot2+=element
                     lumi_tot2 = lumi_par_tot2/13.
                     #print lumi_tot
                     #print lumi_tot2
                     storage.append(lumi_tot/lumi_tot2)
            channel_excl.append(storage)
            #print channel_excl

    print "Done with the file"


print "Now ready to plot"
#this will set different colors in the same plot
num_plots = 14
colormap = plt.cm.gist_ncar
plt.gca().set_prop_cycle(plt.cycler('color', plt.cm.gist_ncar(np.linspace(0, 0.9, num_plots))))


x=range(total_nb4)
labels=[["ch1", "ch2", "ch3", "ch5", "ch6"],[ "ch7", "ch8", "ch9", "ch10", "ch11"],[ "ch12", "ch13", "ch14", "ch15"]]

lgd=0
for alpha in range(14):
    y=[]
    for beta in range(total_nb4):
        y.append(channel_excl[beta][alpha])
    plt.plot(x,y)
    if alpha==4 or alpha==9 or alpha==13:
        plt.legend(labels[lgd], loc = "best", fancybox=True, shadow=True)
        plt.show()
        lgd+=1
Ejemplo n.º 46
0
        self.blue = '#3498db'
        self.red = '#e74c3c'
        self.green = '#2ecc71'
        self.orange = '#e67e22'
        self.yellow = '#f1c40f'
        self.purple = '#9b59b6'
        self.gray = '#95a5a6'
        self.teal = '#1abc9c'
        self.bluegray = '#34495e'

        self.dark_blue = '#2980b9'
        self.dark_red = '#c0392b'
        self.dark_green = '#27ae60'
        self.dark_orange = '#d35400'
        self.dark_yellow = '#f39c12'
        self.dark_purple = '#8e44ad'
        self.dark_gray = '#7f8c8d'
        self.dark_teal = '#16a085'
        self.dark_bluegray = '#2c3e50'

colors = _Colors()

color_sequence = ['blue', 'red', 'green', 'orange', 'purple', 'yellow', 'gray',
                  'teal', 'bluegray']

color_cycle = plt.cycler('color', [colors.__dict__[s] for s in color_sequence])
color_cycle += plt.cycler('mec', [colors.__dict__['dark_{}'.format(s)]
                                  for s in color_sequence])

style = {'axes.prop_cycle': color_cycle}
Ejemplo n.º 47
0
Archivo: cf.py Proyecto: exosports/BART
def cf(date_dir, atmfile, filters, plot=True):
  """
  Call above functions to calculate cf and plot them
  """
  # Read atmfile
  molecules, p, T, abundances = mat.readatm(date_dir + atmfile)
  nlayers = len(p)

  # Read tau.dat
  foo      = date_dir + 'tau.dat'
  tau, wns = readTauDat(foo, nlayers)

  # Calculate BB, reverse the order of p and T
  p = p[::-1]
  T = T[::-1]
  BB = Planck(T, wns)

  # Call cf_eq() to calculate cf
  cf = cf_eq(BB, p, tau, nlayers, wns)

  # Call filter_cf() to calculate cf
  filt_cf, filt_cf_norm = filter_cf(filters, nlayers, wns, cf, normalize=True)

  if plot:
    print("  Plotting contribution functions.\n")
    # Not normalized cf
    plt.figure(4)
    plt.clf()
    gs       = gridspec.GridSpec(1, 2, width_ratios=[5, 1])
    ax0      = plt.subplot(gs[0])
    colormap = plt.cm.rainbow(np.linspace(0, 1, len(filters)))
    ax0.set_prop_cycle(plt.cycler('color', colormap))
    for i in np.arange(len(filt_cf)):
      (head, tail) = os.path.split(filters[i])
      lbl          = tail[:-4]
      ax0.semilogy(filt_cf[i], p, '-', linewidth = 1, label=lbl)
    lgd = ax0.legend(loc='center left', bbox_to_anchor=(1.0, 0.5), 
                     ncol=len(filt_cf)//30 + 1, prop={'size':8})
    ax0.set_ylim(max(p), min(p))
    ax0.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
    ax0.set_xlabel('Contribution Functions', fontsize=14)
    ax0.set_ylabel('Pressure (bar)' , fontsize=14)
    plt.savefig(date_dir + 'ContrFuncs.png', bbox_extra_artists=(lgd,), 
                bbox_inches='tight')

    # Normalized cf
    plt.figure(5)
    plt.clf()
    gs       = gridspec.GridSpec(1, 2, width_ratios=[5, 1])
    ax0      = plt.subplot(gs[0])
    colormap = plt.cm.rainbow(np.linspace(0, 1, len(filters)))
    ax0.set_prop_cycle(plt.cycler('color', colormap))
    for i in np.arange(len(filt_cf_norm)):
      (head, tail) = os.path.split(filters[i])
      lbl          = tail[:-4]
      ax0.semilogy(filt_cf_norm[i], p, '--', linewidth = 1, label=lbl)

    lgd = ax0.legend(loc='center left', bbox_to_anchor=(1,0.5), 
                     ncol=len(filt_cf)//30 + 1, prop={'size':8})
    ax0.set_ylim(max(p), min(p))
    ax0.set_xlim(0, 1.0)
    ax0.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
    ax0.set_xlabel('Normalized Contribution Functions', fontsize=14)
    ax0.set_ylabel('Pressure (bar)' , fontsize=14)
    plt.savefig(date_dir + 'NormContrFuncs.png', bbox_extra_artists=(lgd,), 
                bbox_inches='tight')

  return filt_cf[:,::-1], filt_cf_norm[:,::-1]
Ef = 0.63  # DOS at Fermi level in states/eV
a = 5.6*5.292*(10**(-11))
epsilon = 8.854*10**(-12)  # Permittivity of free space
munot = 4*np.pi*10**(-7)  # vacuum permeability
hbar = 6.58*(10**(-13))  # reduced Plank's constant
T = 200 #K
# Boltzmann's constant
k = 8.6173303*10**(-5)  # in eV.K-1
mu = 0.0  # chemical potential
N0 = Ef/(e*0.5*a**3)
conduct_coeff = N0*(0.33*v**2)*(e**2)*hbar
w_p = np.sqrt(N0*(0.33*v**2)*(e**2)/epsilon)*(hbar/1000)  # plasma frequency in eV

#######################################################################################################################
colormap = plt.cm.plasma
plt.gca().set_prop_cycle(plt.cycler('color', colormap(np.linspace(0, 0.85, num_plots))))

print ("Conductance coefficient:", conduct_coeff, "Plasma Frequency:", w_p)

# Define your own input arrays - can be different (though still within the bounds) than those in the files
# This gives us the flexibility to check for intergation convergence
# We accomplish this by interpolating, soon to follow

#Note: As mentioned above, choose a spacing and endpoints such that w'+w also maps to the w'_array for every w.
# Otherwise one will have to interpolate the self-energy on the w'+w grid for every value of w. that will be unwise.
array_omegap = np.arange(-5, 3, delta_omegap) # The energy grid for the self-energy.
array_omega_a = np.arange(0.002, 0.02, delta_omega) # The energy grid for the incoming infrared photon
array_omega_b = np.arange(0.02, 0.80, delta_omega) # The energy grid for the incoming infrared photon
array_omega = np.concatenate((array_omega_a, array_omega_b))
array_M = interpolate(path_to_realpart, array_omegap)/1000.0
array_Gamma = interpolate(path_to_linewidth, array_omegap)/1000.0
Ejemplo n.º 49
0
def callTransit(atmfile, tepfile,  MCfile, stepsize,  molfit,  solution, p0, 
                tconfig, date_dir, burnin, abun_file, PTtype,  PTfunc, 
                filters, ctf=None):
    """
    Call Transit to produce best-fit outputs.
    Plot MCMC posterior PT plot.

    Parameters:
    -----------
    atmfile: String
       Atmospheric file.
    tepfile: String
       Transiting extra-solar planet file.
    MCfile: String
       File with MCMC log and best-fitting results.
    stepsize: 1D float ndarray
       Specified step sizes for each parameter.
    molfit: 1D String ndarray
       List of molecule names to modify their abundances.
    solution: String
       Flag to indicate transit or eclipse geometry
    p0: Float
       Atmosphere's 'surface' pressure level.
    tconfig: String
       Transit  configuration file.
    date_dir: String
       Directory where to store results.
    burnin: Integer
    abun_file: String
       Elemental abundances file.
    PTtype: String
       Pressure-temperature profile type ('line' for Line et al. 2013, 
       'madhu_noinv' or 'madhu_inv' for Madhusudhan & Seager 2009, 
       'iso' for isothermal)
    PTfunc: pointer to function
       Determines the method of evaluating the PT profile's temperature
    filters: list, strings.
       Filter files associated with the eclipse/transit depths
    ctf: 2D array.
       Contribution or transmittance functions corresponding to `filters`
    """
    # make sure burnin is an integer
    burnin = int(burnin)

    # read atmfile
    molecules, pressure, temp, abundances = mat.readatm(atmfile)
    # get surface gravity
    grav, Rp = mat.get_g(tepfile)
    # get star data if needed
    if PTtype == 'line':
      R_star, T_star, sma, gstar = get_starData(tepfile)
      # FINDME: Hardcoded value:
      T_int  = 100  # K
      PTargs = [R_star, T_star, T_int, sma, grav*1e2]
    else:
      PTargs = None # For non-Line profiles

    # Get best parameters
    bestP, uncer = read_MCMC_out(MCfile)
    allParams    = bestP

    # get PTparams and abundances factors
    nparams   = len(allParams)
    nmol      = len(molfit)
    nradfit   = int(solution == 'transit')
    nPTparams = nparams - nmol - nradfit

    PTparams  = allParams[:nPTparams]

    # call PT profile generator to calculate temperature
    best_T = pt.PT_generator(pressure, PTparams, PTfunc, PTargs)

    # Plot best PT profile
    plt.figure(1)
    plt.clf()
    plt.semilogy(best_T, pressure, '-', color = 'r')
    plt.xlim(0.9*min(best_T), 1.1*max(best_T))
    plt.ylim(max(pressure), min(pressure))
    plt.title('Best PT', fontsize=14)
    plt.xlabel('T (K)'     , fontsize=14)
    plt.ylabel('logP (bar)', fontsize=14)
    # Save plot to current directory
    plt.savefig(date_dir + 'Best_PT.png')

    # Update R0, if needed:
    if nradfit:
      Rp = allParams[nPTparams]

    # write best-fit atmospheric file
    write_atmfile(atmfile, abun_file, molfit, best_T,
                  allParams[nPTparams+nradfit:], date_dir, p0, Rp, grav)

    # write new bestFit Transit config
    if solution == 'transit':
      bestFit_tconfig(tconfig, date_dir, allParams[nPTparams])
    else:
      bestFit_tconfig(tconfig, date_dir)

    # Call Transit with the best-fit tconfig
    Transitdir      = os.path.dirname(os.path.realpath(__file__)) + \
                      "/../modules/transit/"
    bf_tconfig      = date_dir   + 'bestFit_tconfig.cfg'
    Tcall           = Transitdir + "/transit/transit"
    subprocess.call(["{:s} -c {:s}".format(Tcall, bf_tconfig)],
shell=True, cwd=date_dir)

    # ========== plot MCMC PT profiles ==========
    # get MCMC data:
    MCMCdata = date_dir + "/output.npy"
    data = np.load(MCMCdata)
    nchains, npars, niter = np.shape(data)

    # stuck chains:
    data_stack = data[0,:,burnin:]
    for c in np.arange(1, nchains):
        data_stack = np.hstack((data_stack, data[c, :, burnin:]))

    # create array of PT profiles
    PTprofiles = np.zeros((np.shape(data_stack)[1], len(pressure)))

    # current PT parameters for each chain, iteration
    curr_PTparams = PTparams

    # fill-in PT profiles array
    if ctf is None:
        print("  Plotting MCMC PT profile figure.")
    for k in np.arange(0, np.shape(data_stack)[1]):
        j = 0
        for i in np.arange(len(PTparams)):
            if stepsize[i] != 0.0:
                curr_PTparams[i] = data_stack[j,k]
                j +=1
            else:
                pass
        PTprofiles[k] = pt.PT_generator(pressure, curr_PTparams, 
                                        PTfunc, PTargs)

    # get percentiles (for 1,2-sigma boundaries):
    low1   = np.percentile(PTprofiles, 16.0, axis=0)
    hi1    = np.percentile(PTprofiles, 84.0, axis=0)
    low2   = np.percentile(PTprofiles,  2.5, axis=0)
    hi2    = np.percentile(PTprofiles, 97.5, axis=0)
    median = np.median(    PTprofiles,       axis=0)

    # plot figure
    plt.figure(2, dpi=300)
    plt.clf()
    if ctf is not None:
        plt.subplots_adjust(wspace=0.15)
        ax1=plt.subplot(121)
    else:
        ax1=plt.subplot(111)
    ax1.fill_betweenx(pressure, low2, hi2, facecolor="#62B1FF", 
                      edgecolor="0.5")
    ax1.fill_betweenx(pressure, low1, hi1, facecolor="#1873CC",
                      edgecolor="#1873CC")
    plt.semilogy(median, pressure, "-", lw=2, label='Median',color="k")
    plt.semilogy(best_T, pressure, "-", lw=2, label="Best fit", color="r")
    plt.ylim(pressure[0], pressure[-1])
    plt.legend(loc="best")
    plt.xlabel("Temperature  (K)", size=15)
    plt.ylabel("Pressure  (bar)",  size=15)
    if ctf is not None:
        # Add contribution or transmittance functions
        ax2=plt.subplot(122, sharey=ax1)
        colormap = plt.cm.rainbow(np.linspace(0, 1, len(filters)))
        ax2.set_prop_cycle(plt.cycler('color', colormap))
        # Plot with filter labels
        for i in np.arange(len(filters)):
            (head, tail) = os.path.split(filters[i])
            lbl          = tail[:-4]
            ax2.semilogy(ctf[i], pressure, '--',  linewidth = 1, label=lbl)
        # Hide y axis tick labels
        plt.setp(ax2.get_yticklabels(), visible=False)
        # Place legend off figure in case there are many filters
        lgd = ax2.legend(loc='center left', bbox_to_anchor=(1,0.5), 
                         ncol=len(filters)//30 + 1, prop={'size':8})
        if solution == 'eclipse':
            ax2.set_xlabel('Normalized Contribution\nFunctions',  fontsize=15)
        else:
            ax2.set_xlabel('Transmittance', fontsize=15)
    

    # save figure
    if ctf is not None:
        savefile = date_dir + "MCMC_PTprofiles_cf.png"
        plt.savefig(savefile, bbox_extra_artists=(lgd,), bbox_inches='tight')
    else:
        savefile = date_dir + "MCMC_PTprofiles.png"
        plt.savefig(savefile)