Example #1
0
def plot5_1X(minor):
    params = {'figure.figsize': [6.15, 5.0]}
    rcParams.update(params)

    reinforce_epsilon = mmread("./out/ex5_%d_reinforce_epsilon.mtx" % minor)
    enac_epsilon = mmread("./out/ex5_%d_enac_epsilon.mtx" % minor)

    reinforce_action_mean = \
        mmread("./out/ex5_%d_reinforce_action_mean.mtx" % minor)
    reinforce_action_std = \
        mmread("./out/ex5_%d_reinforce_action_std.mtx" % minor)
    enac_action_mean = mmread("./out/ex5_%d_enac_action_mean.mtx" % minor)
    enac_action_std = mmread("./out/ex5_%d_enac_action_std.mtx" % minor)

    actions = [(reinforce_action_mean, reinforce_action_std, reinforce_epsilon,
                "REINFORCE", "Sigma", None, None),
               (enac_action_mean, enac_action_std, enac_epsilon, "ENAC",
                "Sigma", None, None)]

    for ai in [0, 1]:
        figure(ai)
        plot_results(actions, ai, "Action (\%)", "Market Period")
        if tex:
            savefig('./out/fig5_%d_action_a%d.pdf' % (minor, ai + 1))


#            savefig('./out/fig5_%d_action_a%d.eps' % (minor, ai + 1))
        else:
            savefig('./out/fig5_%d_action_a%d.png' % (minor, ai + 1))
Example #2
0
  def __init__(self, tm, showOverlaps=False, showOverlapsValues=False):
    self.tm = tm

    self.showOverlaps = showOverlaps
    self.showOverlapsValues = showOverlapsValues

    self.encodings = []
    self.resets = []
    self.numSegmentsPerCell = []
    self.numSynapsesPerSegment = []

    import matplotlib.pyplot as plt
    self.plt = plt
    import matplotlib.cm as cm
    self.cm = cm

    from pylab import rcParams

    if self.showOverlaps and self.showOverlapsValues:
      rcParams.update({'figure.figsize': (20, 20)})
    else:
      rcParams.update({'figure.figsize': (6, 12)})

    rcParams.update({'figure.autolayout': True})
    rcParams.update({'figure.facecolor': 'white'})
    rcParams.update({'ytick.labelsize': 8})
Example #3
0
    def __init__(self, tm, showOverlaps=False, showOverlapsValues=False):
        self.tm = tm

        self.showOverlaps = showOverlaps
        self.showOverlapsValues = showOverlapsValues

        self.encodings = []
        self.resets = []
        self.numSegmentsPerCell = []
        self.numSynapsesPerSegment = []

        import matplotlib.pyplot as plt
        self.plt = plt
        import matplotlib.cm as cm
        self.cm = cm

        from pylab import rcParams

        if self.showOverlaps and self.showOverlapsValues:
            rcParams.update({'figure.figsize': (20, 20)})
        else:
            rcParams.update({'figure.figsize': (6, 12)})

        rcParams.update({'figure.autolayout': True})
        rcParams.update({'figure.facecolor': 'white'})
        rcParams.update({'ytick.labelsize': 8})
Example #4
0
def getErrorbarFigures(title, X, Ys, stdDevs, plotTitles, xAxisLabel,
                       yAxisLabels, gridFormat):
    """
  Plots the specified data and saves specified plot to file
  """
    rcParams['figure.figsize'] = 15, 15
    fig = plt.figure()
    fig.suptitle(title)
    fig.subplots_adjust(left=None,
                        right=None,
                        bottom=None,
                        top=None,
                        wspace=None,
                        hspace=0.35)
    plt.ion()
    plt.show()
    rcParams.update({'font.size': 12})

    for i, y in enumerate(Ys):
        ax = fig.add_subplot(gridFormat + 1 + i)
        ax.set_title(plotTitles[i])
        ax.set_xlabel(xAxisLabel)
        ax.set_ylabel(yAxisLabels[i])
        ax.axis([0, max(X) + 10, 0, 20])
        ax.errorbar(X, y, stdDevs[i])

    return fig
Example #5
0
def SetForEps(proport=0.75, fig_width_pt=455.24, xylabel_fs=9, leg_fs=8, text_fs=9, xtick_fs=7, ytick_fs=7):
    """
    Set figure proportions
    ======================
    """
    # fig_width_pt = 455.24411                  # Get this from LaTeX using \showthe\columnwidth
    inches_per_pt = 1.0/72.27                   # Convert pt to inch
    fig_width     = fig_width_pt*inches_per_pt  # width in inches
    fig_height    = fig_width*proport           # height in inches
    fig_size      = [fig_width,fig_height]
    #params = {'mathtext.fontset':'stix', # 'cm', 'stix', 'stixsans', 'custom'
    params = {
        'backend'            : 'ps',
        'axes.labelsize'     : xylabel_fs,
        'font.size'          : text_fs,
        'legend.fontsize'    : leg_fs,
        'xtick.labelsize'    : xtick_fs,
        'ytick.labelsize'    : ytick_fs,
        'text.usetex'        : True, # very IMPORTANT to avoid Type 3 fonts
        'ps.useafm'          : True, # very IMPORTANT to avoid Type 3 fonts
        'pdf.use14corefonts' : True, # very IMPORTANT to avoid Type 3 fonts
        'figure.figsize'     : fig_size,
    }
    MPLclose()
    rcdefaults()
    rcParams.update(params)
Example #6
0
def plot5_1X(minor):
    params = {'figure.figsize': [6.15, 5.0]}
    rcParams.update(params)

    reinforce_epsilon = mmread("./out/ex5_%d_reinforce_epsilon.mtx" % minor)
    enac_epsilon = mmread("./out/ex5_%d_enac_epsilon.mtx" % minor)

    reinforce_action_mean = \
        mmread("./out/ex5_%d_reinforce_action_mean.mtx" % minor)
    reinforce_action_std = \
        mmread("./out/ex5_%d_reinforce_action_std.mtx" % minor)
    enac_action_mean = mmread("./out/ex5_%d_enac_action_mean.mtx" % minor)
    enac_action_std = mmread("./out/ex5_%d_enac_action_std.mtx" % minor)

    actions = [
        (reinforce_action_mean, reinforce_action_std, reinforce_epsilon,
         "REINFORCE", "Sigma", None, None),
        (enac_action_mean, enac_action_std, enac_epsilon,
         "ENAC", "Sigma", None, None)
    ]

    for ai in [0, 1]:
        figure(ai)
        plot_results(actions, ai, "Action (\%)", "Market Period")
        if tex:
            savefig('./out/fig5_%d_action_a%d.pdf' % (minor, ai + 1))
#            savefig('./out/fig5_%d_action_a%d.eps' % (minor, ai + 1))
        else:
            savefig('./out/fig5_%d_action_a%d.png' % (minor, ai + 1))
Example #7
0
def do_plot(date, flux, status=0):
    xmin = min(date)
    xmax = max(date)
    ymin = min(flux)
    ymax = max(flux)
    xr = xmax - xmin
    yr = ymax - ymin
    try:
        params = {
            "backend": "png",
            "axes.linewidth": 2.5,
            "axes.labelsize": 24,
            "axes.font": "sans-serif",
            "axes.fontweight": "bold",
            "text.fontsize": 12,
            "legend.fontsize": 12,
            "xtick.labelsize": 16,
            "ytick.labelsize": 16,
        }
        rcParams.update(params)
    except:
        print("ERROR -- KEPCLIP: install latex for scientific plotting")
        status = 1

    if status == 0:
        # 		plt.figure(figsize=[12,5])
        plt.clf()
    # 	plt.axes([0.2,0.2,0.94,0.88])
    # 	ltime = [date[0]]; ldata = [flux[0]]
    # 	for i in range(1,len(flux)):
    #            if (date[i-1] > date[i] - 0.025):
    #                ltime.append(date[i])
    #                ldata.append(flux[i])
    #            else:
    #                ltime = n.array(ltime, dtype='float64')
    #                ldata = n.array(ldata, dtype='float64')
    #                plt.plot(ltime,ldata,color='#0000ff',linestyle='-'
    #                	,linewidth=1.0)
    #                ltime = []; ldata = []
    # 	ltime = n.array(ltime, dtype='float64')
    # 	ldata = n.array(ldata, dtype='float64')

    plt.plot(date, flux, color="#0000ff", linestyle="-", linewidth=1.0)
    date = n.insert(date, [0], [date[0]])
    date = n.append(date, [date[-1]])
    flux = n.insert(flux, [0], [0.0])
    flux = n.append(flux, [0.0])
    plt.fill(date, flux, fc="#ffff00", linewidth=0.0, alpha=0.2)
    plt.xlim(xmin - xr * 0.01, xmax + xr * 0.01)
    if ymin - yr * 0.01 <= 0.0:
        plt.ylim(1.0e-10, ymax + yr * 0.01)
    else:
        plt.ylim(ymin - yr * 0.01, ymax + yr * 0.01)
    xlab = "BJD"
    ylab = "e- / cadence"
    plt.xlabel(xlab, {"color": "k"})
    plt.ylabel(ylab, {"color": "k"})
    plt.ion()
    plt.grid()
    plt.ioff()
def days_of_week_spending(file_data):
    rcParams['figure.figsize'] = [16, 9]
    rcParams.update({'figure.autolayout': True})
    sns.set(style="dark")
    df = pd.read_csv(file_data)
    df["category"] = df["category"].map(all_categories)
    df["cost"] = df["cost"].astype("float64")
    df["cost"] = df["cost"].apply(lambda x: x / 100)
    m = file_data.index(".")
    result = df.groupby(["dayOfWeek", "category"])["cost"] \
        .agg([np.sum]) \
        .reindex(['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', "Вс"], level='dayOfWeek')
    g = result["sum"].groupby(level=0, group_keys=False) \
        .nlargest(4)

    gr = sns.factorplot(x="dayOfWeek",
                        y="sum",
                        hue="category",
                        data=g.reset_index(),
                        kind="bar",
                        palette="Paired",
                        size=6,
                        aspect=1.5,
                        legend=False)
    plt.legend(loc='upper right')
    gr.savefig(file_data[:m] + "_plot.png")
    plt.clf()
Example #9
0
def SetForPng(proport=0.75,
              fig_width_pt=455.24,
              dpi=150,
              xylabel_fs=9,
              leg_fs=8,
              text_fs=9,
              xtick_fs=7,
              ytick_fs=7):
    """
    Set figure proportions
    ======================
    """
    inches_per_pt = 1.0 / 72.27  # Convert pt to inch
    fig_width = fig_width_pt * inches_per_pt  # width in inches
    fig_height = fig_width * proport  # height in inches
    fig_size = [fig_width, fig_height]
    params = {
        'axes.labelsize': xylabel_fs,
        'font.size': text_fs,
        'legend.fontsize': leg_fs,
        'xtick.labelsize': xtick_fs,
        'ytick.labelsize': ytick_fs,
        'figure.figsize': fig_size,
        'savefig.dpi': dpi,
    }
    #utl.Ff(&bb, "SetFontSize(%s)\n", args)
    #utl.Ff(&bb, "rcParams.update({'savefig.dpi':%d})\n", dpi)
    MPLclose()
    rcdefaults()
    rcParams.update(params)
Example #10
0
def SetForEps(proport=0.75,
              fig_width_pt=455.24,
              xylabel_fs=9,
              leg_fs=8,
              text_fs=9,
              xtick_fs=7,
              ytick_fs=7,
              text_usetex=True,
              mplclose=True):
    """
    Set figure proportions
    ======================
    """
    # fig_width_pt = 455.24411                  # Get this from LaTeX using \showthe\columnwidth
    inches_per_pt = 1.0 / 72.27  # Convert pt to inch
    fig_width = fig_width_pt * inches_per_pt  # width in inches
    fig_height = fig_width * proport  # height in inches
    fig_size = [fig_width, fig_height]
    #params = {'mathtext.fontset':'stix', # 'cm', 'stix', 'stixsans', 'custom'
    params = {
        'backend': 'ps',
        'axes.labelsize': xylabel_fs,
        'font.size': text_fs,
        'legend.fontsize': leg_fs,
        'xtick.labelsize': xtick_fs,
        'ytick.labelsize': ytick_fs,
        'text.usetex': text_usetex,  # very IMPORTANT to avoid Type 3 fonts
        'ps.useafm': True,  # very IMPORTANT to avoid Type 3 fonts
        'pdf.use14corefonts': True,  # very IMPORTANT to avoid Type 3 fonts
        'figure.figsize': fig_size,
    }
    if mplclose: MPLclose()
    rcdefaults()
    rcParams.update(params)
Example #11
0
def do_plot(date,flux,status=0):
	xmin = min(date)
	xmax = max(date)
	ymin = min(flux)
	ymax = max(flux)
	xr = xmax - xmin
	yr = ymax - ymin
	try:
		params = {'backend': 'png','axes.linewidth': 2.5,
			'axes.labelsize': 24,
			'axes.font': 'sans-serif',
			'axes.fontweight' : 'bold',
			'text.fontsize': 12,
			'legend.fontsize': 12,
			'xtick.labelsize': 16,
			'ytick.labelsize': 16}
		rcParams.update(params)
	except:
		print 'ERROR -- KEPCLIP: install latex for scientific plotting'
		status = 1

	if status == 0:
#		plt.figure(figsize=[12,5])
		plt.clf()
#	plt.axes([0.2,0.2,0.94,0.88])
#	ltime = [date[0]]; ldata = [flux[0]]
#	for i in range(1,len(flux)):
#            if (date[i-1] > date[i] - 0.025):
#                ltime.append(date[i])
#                ldata.append(flux[i])
#            else:
#                ltime = n.array(ltime, dtype='float64')
#                ldata = n.array(ldata, dtype='float64')
#                plt.plot(ltime,ldata,color='#0000ff',linestyle='-'
#                	,linewidth=1.0)
#                ltime = []; ldata = []
#	ltime = n.array(ltime, dtype='float64')
#	ldata = n.array(ldata, dtype='float64')

	plt.plot(date,flux,color='#0000ff',linestyle='-',linewidth=1.0)
	date = n.insert(date,[0],[date[0]]) 
	date = n.append(date,[date[-1]])
	flux = n.insert(flux,[0],[0.0]) 
	flux = n.append(flux,[0.0])
	plt.fill(date,flux,fc='#ffff00',linewidth=0.0,alpha=0.2)
	plt.xlim(xmin-xr*0.01,xmax+xr*0.01)
	if ymin-yr*0.01 <= 0.0:
		plt.ylim(1.0e-10,ymax+yr*0.01)
	else:
		plt.ylim(ymin-yr*0.01,ymax+yr*0.01)
	xlab = 'BJD'
	ylab = 'e- / cadence'
	plt.xlabel(xlab, {'color' : 'k'})
	plt.ylabel(ylab, {'color' : 'k'})
        plt.ion()
	plt.grid()
	plt.ioff()
Example #12
0
def pylab_setup():
    from pylab import rcParams
    params = {'backend': 'qt',
              'axes.labelsize': 8,
              'text.fontsize': 8,
              'legend.fontsize': 10,
              'xtick.labelsize': 8,
              'ytick.labelsize': 8}
    rcParams.update(params)
def matrc4X6():
    MatPlotParams = {'axes.titlesize': 12, 'axes.linewidth' : 1.0, 'axes.labelsize': 12, 'xtick.labelsize': 10, 'ytick.labelsize': 10, 'xtick.major.size': 12, 'ytick.major.size' : 12, 'xtick.minor.size': 10, 'ytick.minor.size': 10, 'figure.figsize' : [12.0, 10.0], 'xtick.major.pad' : 6, 'ytick.major.pad' : 4, 'figure.subplot.hspace' : 0.0}
    rcParams.update(MatPlotParams)
    pylab.subplots_adjust(left = 0.07,  # the left side of the subplots of the figure
                          right = 0.97,    # the right side of the subplots of the figure
                          bottom = 0.05,   # the bottom of the subplots of the figure
                          top = 0.95,      # the top of the subplots of the figure
                          wspace = 0.15,   # the amount of width reserved for blank space between subplots
                          hspace = 0.15)   # the amount of height reserved for white space between subplots
def galplot6():
    MatPlotParams = {'axes.titlesize': 12, 'axes.linewidth' : 1.0, 'axes.labelsize': 12, 'xtick.labelsize': 10, 'ytick.labelsize': 10, 'xtick.major.size': 12, 'ytick.major.size' : 12, 'xtick.minor.size': 10, 'ytick.minor.size': 10, 'figure.figsize' : [10.0, 10.5], 'xtick.major.pad' : 6, 'ytick.major.pad' : 6, 'figure.subplot.hspace' : 0.0,'legend.fontsize': 10}
    rcParams.update(MatPlotParams)
    pylab.subplots_adjust(left = 0.2,  # the left side of the subplots of the figure
                          right = 0.8,    # the right side of the subplots of the figure
                          bottom = 0.1,#.05   # the bottom of the subplots of the figure
                          top = 0.95,      # the top of the subplots of the figure
                          wspace = 0.30,   # the amount of width reserved for blank space between subplots
                          hspace = 0.45)#.15   # the amount of height reserved for white space between subplots
Example #15
0
def imsave(filename, data, **kwargs):
    figsize = (pylab.array(data.shape) / 100.0)[::-1]
    rcParams.update({'figure.figsize': figsize})
    fig = pylab.figure(figsize=figsize)
    pylab.axes([0, 0, 1, 1])
    pylab.axis('off')
    fig.set_size_inches(figsize)
    pylab.imshow(data, origin='lower', **kwargs)
    pylab.savefig(filename, facecolor='black', edgecolor='black', dpi=100)
    pylab.close(fig)
Example #16
0
def imsave( filename, data, **kwargs ):
	figsize = (pylab.array(data.shape)/100.0)[::-1]
	rcParams.update( {'figure.figsize':figsize} )
	fig = pylab.figure( figsize=figsize )
	pylab.axes( [0,0,1,1] )
	pylab.axis( 'off' )
	fig.set_size_inches( figsize )
	pylab.imshow( data, origin='lower', **kwargs )
	pylab.savefig( filename, facecolor='black', edgecolor='black', dpi=100 )
	pylab.close( fig )
Example #17
0
    def graphEpocs(self):
        """Graph the average k-fold training and test error for all tested epocs"""
        rcParams.update(self._PRAMS)

        plot(self.epocsRange, self.epocsErrors[0], 'r-', label="Training Error", linewidth=2)
        plot(self.epocsRange, self.epocsErrors[1], 'b-', label="Test Error", linewidth=2)
        xlabel('Number Epocs')
        ylabel('Error')
        title('Epocs vs Error')
        legend()
        show()
Example #18
0
def mhd_shocktube(P, x=(0,1), **kwargs):

    from pylab import sqrt, linspace, subplot, plot, text, xlabel, figure, show
    from pylab import subplots_adjust, setp, gca, LinearLocator, rcParams, legend

    rho, pre   = P[:,0], P[:,1]
    vx, vy, vz = P[:,2], P[:,3], P[:,4]
    Bx, By, Bz = P[:,5], P[:,6], P[:,7]

    plot_args = { }
    plot_args['marker'] = kwargs.get('marker', 'o')
    plot_args['c'     ] = kwargs.get('c'     , 'k')
    plot_args['mfc'   ] = kwargs.get('mfc'   , 'None')

    plot_args.update(kwargs)
    rcParams.update({'axes.labelsize':16, 'ytick.major.pad':8})

    X = linspace(x[0],x[1],P.shape[0])
    g = 1 / sqrt(1-(vx**2+vy**2+vz**2))

    ax = subplot(2,3,1)
    plot(X,rho, **plot_args)
    text(0.9,0.85, r"$\rho$", transform = ax.transAxes, fontsize=20)
    setp(ax.get_xticklabels(), visible=False)
    if 'label' in plot_args: legend(loc='upper left')

    ax = subplot(2,3,2)
    plot(X,pre, **plot_args)
    text(0.9,0.85, r"$P$", transform = ax.transAxes, fontsize=20)
    setp(ax.get_xticklabels(), visible=False)

    ax = subplot(2,3,3)
    plot(X, g, **plot_args)
    text(0.9,0.85, r"$\gamma$", transform = ax.transAxes, fontsize=20)
    setp(ax.get_xticklabels(), visible=False)

    ax = subplot(2,3,4)
    plot(X, vx, **plot_args)
    text(0.9,0.85, r"$v_x$", transform = ax.transAxes, fontsize=20)
    xlabel(r"$x$")

    ax = subplot(2,3,5)
    plot(X, vy, **plot_args)
    text(0.9,0.85, r"$v_y$", transform = ax.transAxes, fontsize=20)
    xlabel(r"$x$")

    ax = subplot(2,3,6)
    plot(X, By, **plot_args)
    text(0.9,0.85, r"$B_y$", transform = ax.transAxes, fontsize=20)
    xlabel(r"$x$")

    subplots_adjust(hspace=0.15)
Example #19
0
def SetFontSize(xylabel_fs=9, leg_fs=8, text_fs=9, xtick_fs=7, ytick_fs=7):
    """
    Set font sizes
    ==============
    """
    params = {
        'axes.labelsize'  : xylabel_fs,
        'legend.fontsize' : leg_fs,
        'font.size'       : text_fs,
        'xtick.labelsize' : xtick_fs,
        'ytick.labelsize' : ytick_fs,
    }
    rcParams.update(params)
Example #20
0
    def plot_weather(self, start, end):
        df = self.read_weather(start, end).dropna().reset_index()
        df['weather'] = df.apply(self.weather_category, axis=1)

        from pylab import rcParams
        rcParams['figure.figsize'] = 40, 10
        rcParams.update({'font.size': 22})
        weather_df = df.groupby(['month', 'weather'
                                 ]).aqi.count().unstack().reset_index()
        weather_df.plot.bar(
            x='month',
            y=[rain_index, overcast_index, cloudy_index, sunny_index])
        plt.show()
Example #21
0
def SetFontSize(xylabel_fs=9, leg_fs=8, text_fs=9, xtick_fs=7, ytick_fs=7):
    """
    Set font sizes
    ==============
    """
    params = {
        'axes.labelsize': xylabel_fs,
        'legend.fontsize': leg_fs,
        'font.size': text_fs,
        'xtick.labelsize': xtick_fs,
        'ytick.labelsize': ytick_fs,
    }
    rcParams.update(params)
Example #22
0
def SetFontSize(xylabel_fs=9, leg_fs=8, text_fs=9, xtick_fs=7, ytick_fs=7):
    """
    Set font sizes
    ==============
    """
    params = {
        "axes.labelsize": xylabel_fs,
        "legend.fontsize": leg_fs,
        "font.size": text_fs,
        "xtick.labelsize": xtick_fs,
        "ytick.labelsize": ytick_fs,
    }
    rcParams.update(params)
def categories_spending(file_data):
    rcParams['figure.figsize'] = [16, 9]
    rcParams.update({'figure.autolayout': True})

    df = pd.read_csv(file_data)
    df["category"] = df["category"].map(all_categories)
    df["cost"] = df["cost"].astype("float64")
    df["cost"] = df["cost"].apply(lambda x: x / 100)
    m = file_data.index(".")

    ax = df.groupby(["category", "date"])["cost"] \
        .sum().unstack("category").plot()
    plt.legend(loc='upper right')
    plt.savefig(file_data[:m] + "_plot.png")
    plt.clf()
def pub_plots(xmaj = 5, xmin = 1, xstr = '%03.2f', ymaj = 5, ymin = 1, ystr = '%d'):
    MatPlotParams = {'axes.yaxis.labelpad': 10,'axes.xaxis.labelpad': 10, 'axes.titlesize': 10, 'axes.linewidth' : 1.5, 'axes.labelsize': 10, 'xtick.labelsize': 10, 'ytick.labelsize': 10, 'xtick.major.size': 8, 'ytick.major.size' : 8, 'xtick.minor.size': 4, 'ytick.minor.size': 4, 'xtick.major.pad' : 6, 'ytick.major.pad' : 6}
    rcParams.update(MatPlotParams)
    
    xmajLocator   = MultipleLocator(xmaj)
    xmajFormatter = FormatStrFormatter(xstr)
    xminLocator   = MultipleLocator(xmin)
    
    ymajLocator   = MultipleLocator(ymaj)
    ymajFormatter = FormatStrFormatter(ystr)
    yminLocator   = MultipleLocator(ymin)
    
    data_holder = plot_dats(xmajLocator, xmajFormatter, xminLocator, ymajLocator,
                 ymajFormatter, yminLocator)
    return data_holder
Example #25
0
def SetForEps (proport=0.75, fig_width_pt=455.24):
    # fig_width_pt = 455.24411                  # Get this from LaTeX using \showthe\columnwidth
    inches_per_pt = 1.0/72.27                   # Convert pt to inch
    fig_width     = fig_width_pt*inches_per_pt  # width in inches
    fig_height    = fig_width*proport           # height in inches
    fig_size      = [fig_width,fig_height]
    params = {'mathtext.fontset':'stix', # 'cm', 'stix', 'stixsans', 'custom'
              'backend':         'ps',
              'axes.labelsize':  10,
              'text.fontsize':   10,
              'legend.fontsize': 8,
              'xtick.labelsize': 8,
              'ytick.labelsize': 8,
              'text.usetex':     False,
              'figure.figsize': fig_size}
    rcParams.update(params)
Example #26
0
def SetForEps (proport=0.75, fig_width_pt=455.24):
    # fig_width_pt = 455.24411                  # Get this from LaTeX using \showthe\columnwidth
    inches_per_pt = 1.0/72.27                   # Convert pt to inch
    fig_width     = fig_width_pt*inches_per_pt  # width in inches
    fig_height    = fig_width*proport           # height in inches
    fig_size      = [fig_width,fig_height]
    params = {'mathtext.fontset':'stix', # 'cm', 'stix', 'stixsans', 'custom'
              'backend':         'ps',
              'axes.labelsize':  10,
              'text.fontsize':   10,
              'legend.fontsize': 8,
              'xtick.labelsize': 8,
              'ytick.labelsize': 8,
              'text.usetex':     False,
              'figure.figsize': fig_size}
    rcParams.update(params)
Example #27
0
def DrawCrossover(A, B, a, b, pos):
    """
    DrawCrossover draws crossover process
    """
    rcParams.update({'figure.figsize':[800/72.27,400/72.27]})
    DrawChromo('A', A, pos, 0.35, 0)
    DrawChromo('B', B, pos, 0.25, 1)
    DrawChromo('a', a, pos, 0.10, 0, blue='#e3a9a9')
    DrawChromo('b', b, pos, 0.00, 0, red='#c8d0e3')
    axis('equal')
    axis([0, 1.2, 0, 0.4])
    gca().get_yaxis().set_visible(False)
    gca().get_xaxis().set_visible(False)
    for dir in ['left', 'right', 'top', 'bottom']:
        gca().spines[dir].set_visible(False)
    gca().add_patch(FancyArrowPatch([0.6,0.25], [0.6, 0.2], fc='#9fffde', mutation_scale=30))
def plotExperimentState(runner, plotVerbosity, numWorlds, numElems, isOnline, experimentPhase):
    if plotVerbosity >= 1:
        rcParams["figure.figsize"] = PLOT_WIDTH, PLOT_HEIGHT
        rcParams.update({"font.size": 14})
        title = "worlds: {0}, elements: {1}, online: {2}, phase: {3}".format(
            numWorlds, numElems, isOnline, experimentPhase
        )
        # runner.tp.mmGetPlotConnectionsPerColumn(title=title)
        if plotVerbosity >= 2:
            # runner.tm.mmGetCellActivityPlot(title=title, activityType="activeCells",
            #                                 showReset=True,
            #                                 resetShading=PLOT_RESET_SHADING)
            # runner.tm.mmGetCellActivityPlot(title=title,
            #                                 activityType="predictedActiveCells",
            #                                 showReset=True,
            #                                 resetShading=PLOT_RESET_SHADING)
            runner.tp.mmGetCellActivityPlot(title=title, showReset=True, resetShading=PLOT_RESET_SHADING)
            writeToCsv(runner)
def plotExperimentState(runner, plotVerbosity, numWorlds, numElems, isOnline,
                        experimentPhase):
  if plotVerbosity >= 1:
    rcParams['figure.figsize'] = PLOT_WIDTH, PLOT_HEIGHT
    rcParams.update({'font.size': 14})
    title = "worlds: {0}, elements: {1}, online: {2}, phase: {3}".format(
            numWorlds, numElems, isOnline, experimentPhase)
    # runner.tp.mmGetPlotConnectionsPerColumn(title=title)
    if plotVerbosity >= 2:
      # runner.tm.mmGetCellActivityPlot(title=title, activityType="activeCells",
      #                                 showReset=True,
      #                                 resetShading=PLOT_RESET_SHADING)
      # runner.tm.mmGetCellActivityPlot(title=title,
      #                                 activityType="predictedActiveCells",
      #                                 showReset=True,
      #                                 resetShading=PLOT_RESET_SHADING)
      runner.tp.mmGetCellActivityPlot(title=title, showReset=True,
                                      resetShading=PLOT_RESET_SHADING)
      writeToCsv(runner)
def aniStep(step):   
    mesh.inject(int(1.1e6/mesh.dt/frames))
    with plt.style.context('fivethirtyeight'):
        rcParams.update({'figure.autolayout': True})
        
        gs = gridspec.GridSpec(2, 2) 
        AC = plt.subplot(gs[:,0])
        #BW = plt.subplot(gs[:,3:])
        AC.scatter(ArrowCanyon.d13c,ArrowCanyon.SAMP_HEIGHT,s=10,color=[.7,.7,.7],edgecolor='none')
        AC.set_xlabel('$\delta$13C')
        AC.set_ylabel('height(m)')
        AC.set_ylim([0,120])
        AC.set_xlim([-10,6])
        BattleshipWash.d44ca=BattleshipWash.d44ca[BattleshipWash.d44ca<-.9]
        cmin=round(np.min([ArrowCanyon.d44ca.min(),BattleshipWash.d44ca.min()]),1)
        cmax=round(np.max([ArrowCanyon.d44ca.max(),BattleshipWash.d44ca.max()]),1)
        specCM=plt.get_cmap('Spectral') 
        minCa=-1.4
        rangeCa=.4
        for i in range(meshX-1):
            avCa=np.mean(mesh.printBox('rock','d44ca')[1,i:i+2])
            AC.plot(mesh.printBox('rock','d13c')[1,i:i+2],np.linspace(meshX-(i-1),meshX-i,2),color=specCM(np.abs(minCa-avCa)/rangeCa))
        AC.scatter(BattleshipWash.d13c,BattleshipWash.SAMP_HEIGHT-240.0,s=10,color=[.7,.7,.7],edgecolor='none')
        cmax=-1.0
        d44ca=AC.scatter(ArrowCanyon.d13c,ArrowCanyon.SAMP_HEIGHT,c=ArrowCanyon.d44ca,cmap='Spectral',vmin=cmin,vmax=cmax,s=25,edgecolor=[.2,.2,.2])
        cbar=fig.colorbar(d44ca,ax=AC,label='$\delta$44Ca', orientation='vertical',pad=.05,shrink=.4,ticks=[ round(a, 1) for a in np.linspace(cmin,cmax,7)])
        d44ca=AC.scatter(BattleshipWash.d13c,BattleshipWash.SAMP_HEIGHT-240.0,c=BattleshipWash.d44ca,cmap=viridis,s=25,edgecolor=[.2,.2,.2],vmin=cmin,vmax=cmax)
        #cbar=fig.colorbar(d44ca,ax=AC,label='$\delta$44Ca', orientation='vertical',pad=.01,shrink=.25,ticks=[ round(a, 1) for a in np.linspace(cmin,cmax,7)])
        #fig.savefig('CaData.pdf', format='pdf', dpi=300)
        
        Xplt = plt.subplot(gs[0,1])
        Xplt2 = plt.subplot(gs[1,1])
        Xplt.plot(mesh.printBox('rock','d13c')[1,:],mesh.printBox('rock','d44ca')[1,:],color=plt.rcParams['axes.color_cycle'][0])
        Xplt.plot(ArrowCanyon.d13c,ArrowCanyon.d44ca,markeredgecolor='none',linestyle='none',marker='o',color=plt.rcParams['axes.color_cycle'][1])
        Xplt2.plot(mesh.printBox('rock','d18o')[1,:],mesh.printBox('rock','d44ca')[1,:],color=plt.rcParams['axes.color_cycle'][0])
        Xplt2.plot(ArrowCanyon.d18o,ArrowCanyon.d44ca,markeredgecolor='none',linestyle='none',marker='o',color=plt.rcParams['axes.color_cycle'][1])
        
        Xplt.set_xlabel('$\delta$13C')
        Xplt.set_ylabel('$\delta$44Ca')
        Xplt.set_xlim(-8,3.0)
        Xplt2.set_xlabel('$\delta$18O')
        Xplt2.set_xlim(-8,0.0)
        Xplt2.set_ylabel('$\delta$44Ca')
Example #31
0
  def __init__(self, encoder):
    self.encoder = encoder

    self.sensor = []
    self.encoding = []
    self.steer = []
    self.reward = []
    self.value = []
    self.qValues = defaultdict(lambda: [])
    self.bestAction = []

    import matplotlib.pyplot as plt
    self.plt = plt
    import matplotlib.cm as cm
    self.cm = cm

    from pylab import rcParams
    rcParams.update({'figure.figsize': (6, 9)})
    # rcParams.update({'figure.autolayout': True})
    rcParams.update({'figure.facecolor': 'white'})
Example #32
0
    def __init__(self, encoder):
        self.encoder = encoder

        self.sensor = []
        self.encoding = []
        self.steer = []
        self.reward = []
        self.value = []
        self.qValues = defaultdict(lambda: [])
        self.bestAction = []

        import matplotlib.pyplot as plt
        self.plt = plt
        import matplotlib.cm as cm
        self.cm = cm

        from pylab import rcParams
        rcParams.update({'figure.figsize': (6, 9)})
        # rcParams.update({'figure.autolayout': True})
        rcParams.update({'figure.facecolor': 'white'})
Example #33
0
def plot6_1():
    if paper:
        fig_width = 3.0  # width in inches
        fig_height = 4.0  # height in inches
        params = {
            'axes.titlesize': 8,
            'axes.labelsize': 6,
            'text.fontsize': 6,
            'legend.fontsize': 5,
            'xtick.labelsize': 6,
            'ytick.labelsize': 6,
            'figure.figsize': [fig_width, fig_height]
        }
        rcParams.update(params)
    else:
        fig_width = 6.15  # width in inches
        fig_height = 5.0  # height in inches
        params = {'figure.figsize': [fig_width, fig_height]}
        rcParams.update(params)

    re_mean = mmread("./out/ex6_1/ex6_1_rotherev_reward_mean.mtx")
    sre_mean = mmread("./out/ex6_1/ex6_1_statefulre_reward_mean.mtx")
    q_mean = mmread("./out/ex6_1/ex6_1_q_reward_mean.mtx")

    rewards = [(re_mean, None, None, None, "Roth-Erev"),
               (q_mean, None, None, None, "Q-Learning"),
               (sre_mean, None, None, None, "Stateful RE")]
    figure()
    plot_agents(rewards,
                r"Reward (\verb+$+)",
                agents=[0, 3],
                fmt=["w^", "wo", "kp"])

    if tex:
        if paper:
            subplots_adjust(bottom=0.07, top=0.94, hspace=0.25)
        else:
            subplots_adjust(hspace=0.3)
        savefig('./out/ex6_1/fig6_1.pdf')
    else:
        savefig('./out/ex6_1/fig6_1.png')
Example #34
0
def getErrorbarFigures(title, X, Ys, stdDevs, plotTitles, xAxisLabel, yAxisLabels, gridFormat):
    """
  Plots the specified data and saves specified plot to file
  """
    rcParams["figure.figsize"] = 15, 15
    fig = plt.figure()
    fig.suptitle(title)
    fig.subplots_adjust(left=None, right=None, bottom=None, top=None, wspace=None, hspace=0.35)
    plt.ion()
    plt.show()
    rcParams.update({"font.size": 12})

    for i, y in enumerate(Ys):
        ax = fig.add_subplot(gridFormat + 1 + i)
        ax.set_title(plotTitles[i])
        ax.set_xlabel(xAxisLabel)
        ax.set_ylabel(yAxisLabels[i])
        ax.axis([0, max(X) + 10, 0, 20])
        ax.errorbar(X, y, stdDevs[i])

    return fig
Example #35
0
def scl_shocktube(P, x=(0,1), **kwargs):

    from pylab import sqrt, linspace, subplot, plot, text, xlabel, figure, show
    from pylab import subplots_adjust, setp, gca, LinearLocator, rcParams, legend

    rho = P[:,0]

    plot_args = { }
    plot_args['marker'] = kwargs.get('marker', 'o')
    plot_args['c'     ] = kwargs.get('c'     , 'k')
    plot_args['mfc'   ] = kwargs.get('mfc'   , 'None')

    plot_args.update(kwargs)
    rcParams.update({'axes.labelsize':16, 'ytick.major.pad':8})

    X = linspace(x[0],x[1],P.shape[0])

    ax = subplot(1,1,1)
    plot(X,rho, **plot_args)
    text(0.9,0.85, r"$\rho$", transform = ax.transAxes, fontsize=20)
    if 'label' in plot_args: legend(loc='upper left')
Example #36
0
def set_plot_style_for_paper():
    params = {
        'axes.labelsize': 18,
        'font.size': 18,
        'legend.fontsize': 18,
        'xtick.labelsize': 18,
        'ytick.labelsize': 18,
        'text.usetex': True,
        #'figure.figsize': [4.5, 4.5],
        'figure.facecolor': 'w',
        'figure.edgecolor': 'w',
        'axes.facecolor': 'w',
        'axes.edgecolor': 'gray',
        'savefig.facecolor': 'w',
        'savefig.edgecolor': 'g',
        'savefig.pad_inches': 0.1,
        'savefig.transparent': True,
        'axes.titlepad': 20,
        'axes.titlesize': 19
    }
    rcParams.update(params)
Example #37
0
    def graphHL(self, styles):
        """ 
        Use matplotlib to plot error rates. styles is a list of line styles. Length of styles needs to be 
        equal to length of rangeHiddenUnits (One for every level of hidden units tested).
        """
        if self.rangeLearningRate == None or self.errorsHL == None:
            raise ValueError, 'Must call calcHAndL before calling  graphHL' 
        
        if len(styles) < len(self.rangeHiddenUnits):
            raise ValueError, 'Must have one style for every level of hidden units tested' 
        
        rcParams.update(self._PRAMS)

        for i,h in enumerate(self.rangeHiddenUnits):
            plot(self.rangeLearningRate, self.errorsHL[i], styles[i], label="h="+str(h), linewidth=2)

        xlabel('Learning Rate')
        ylabel('Error')
        title('Error for Hidden Units and Learning Rate')
        legend()
        show()
Example #38
0
  def __init__(self, field, vehicle, scorer, model):
    self.field = field
    self.vehicle = vehicle
    self.scorer = scorer
    self.model = model

    import matplotlib.pyplot as plt
    self.plt = plt
    import matplotlib.cm as cm
    self.cm = cm

    from pylab import rcParams
    rcParams.update({'figure.figsize': (8, 14)})
    rcParams.update({'figure.autolayout': True})
    rcParams.update({'figure.facecolor': 'white'})

    self.plt.ion()
    self.plt.show()

    self.positions = []
    self.sensorValues = []
    self.sensorNoiseAmounts = []
    self.motorValues = []
    self.motorNoiseAmounts = []
    self.scores = []
    self.goalValues = []
def do_band(gal, band, pos):
    cmd = 'select a.objid, a.petroR50_{band}, a.petromag_{band}-a.extinction_{band}, a.petroR50_r/0.396, b.BT, b.m_tot-a.extinction_{band}, m.probaE  from {band}_band_serexp as b, CAST as a, M2010 as m where a.galcount = m.galcount and a.galcount = b.galcount and a.galcount = {galcount};'.format(band=band, galcount=gal)
    print cmd
    objid, petrorad, petromag, hrad,BT, mag_tot, probaE = cursor.get_data(cmd)
    objid = objid[0]
    petromag = petromag[0]
    petrorad = petrorad[0]
    hrad = hrad[0]
    BT = BT[0]
    mag_tot = mag_tot[0]
    probaE = probaE[0]


    fig.add_subplot(1,3,pos)
    pticks = pub_plots(xmaj = 10, xmin = 5, xstr = '%d', ymaj = 10, ymin = 5, ystr = '%d')
    MatPlotParams = {'xtick.major.pad' :10, 'ytick.major.pad' :10,'xtick.minor.pad' :10, 'ytick.minor.pad' :10, 'axes.labelsize': 8, 'xtick.labelsize': 8, 'ytick.labelsize': 8}
    rcParams.update(MatPlotParams)
    data = load_image('/media/SDSS2/fit_catalog/data/{band}/{folder}/{galcount}_{band}_stamp.fits'.format(band=band, galcount='%08d' %gal, folder = '%04d' %((gal-1)/250 +1)))
    data = resize_image(data, hrad)
    data = np.log10(data)
    zmin, zmax = make_panel(data, pticks, color = cm.gray_r, zmin=2.0*np.nanmin(data)-np.percentile(np.extract(np.isnan(data)==0,data), 95.0))
    pl.title('{band}-band'.format(band=band),fontsize=12)
    ax = pl.gca()
    pl.text(0.05, 0.9, 'm$_{petro}$=%3.1f' %(petromag), 
            fontsize=fsize, 
            horizontalalignment='left', verticalalignment='center',
            transform=ax.transAxes)
    pl.text(0.95, 0.9, 'r$_{petro}$=%4.2f"' %(petrorad), 
            fontsize=fsize, 
            horizontalalignment='right', verticalalignment='center',
            transform=ax.transAxes)
    pl.text(0.05, 0.1, 'galnum=%s' %gal, fontsize=fsize, 
            horizontalalignment='left', verticalalignment='center',
            transform=ax.transAxes)
    pl.text(0.95, 0.1, 'P(Early)=%03.2f' %(probaE), 
            fontsize=fsize, 
            horizontalalignment='right', verticalalignment='center',
            transform=ax.transAxes)
   
    return
Example #40
0
    def __init__(self, field, vehicle, scorer, model):
        self.field = field
        self.vehicle = vehicle
        self.scorer = scorer
        self.model = model

        import matplotlib.pyplot as plt
        self.plt = plt
        import matplotlib.cm as cm
        self.cm = cm

        from pylab import rcParams
        rcParams.update({'figure.figsize': (8, 14)})
        rcParams.update({'figure.autolayout': True})
        rcParams.update({'figure.facecolor': 'white'})

        self.plt.ion()
        self.plt.show()

        self.positions = []
        self.sensorValues = []
        self.sensorNoiseAmounts = []
        self.motorValues = []
        self.motorNoiseAmounts = []
        self.scores = []
        self.goalValues = []
Example #41
0
def SetForPng(proport=0.75, fig_width_pt=455.24, dpi=150, xylabel_fontsize=9,
        leg_fontsize=8, text_fontsize=9, xtick_fontsize=7, ytick_fontsize=7):
    """
    Set figure proportions
    ======================
    """
    inches_per_pt = 1.0/72.27                   # Convert pt to inch
    fig_width     = fig_width_pt*inches_per_pt  # width in inches
    fig_height    = fig_width*proport           # height in inches
    fig_size      = [fig_width,fig_height]
    params = {
        'axes.labelsize'  : xylabel_fontsize,
        'font.size'       : text_fontsize,
        'legend.fontsize' : leg_fontsize,
        'xtick.labelsize' : xtick_fontsize,
        'ytick.labelsize' : ytick_fontsize,
        'figure.figsize'  : fig_size,
        'savefig.dpi'     : dpi,
    }
    MPLclose()
    rcdefaults()
    rcParams.update(params)
Example #42
0
def plot6_1():
    if paper:
        fig_width = 3.0 # width in inches
        fig_height = 4.0 # height in inches
        params = {'axes.titlesize': 8,
                  'axes.labelsize': 6,
                  'text.fontsize': 6,
                  'legend.fontsize': 5,
                  'xtick.labelsize': 6,
                  'ytick.labelsize': 6,
                  'figure.figsize': [fig_width, fig_height]}
        rcParams.update(params)
    else:
        fig_width = 6.15 # width in inches
        fig_height = 5.0 # height in inches
        params = {'figure.figsize': [fig_width, fig_height]}
        rcParams.update(params)

    re_mean = mmread("./out/ex6_1/ex6_1_rotherev_reward_mean.mtx")
    sre_mean = mmread("./out/ex6_1/ex6_1_statefulre_reward_mean.mtx")
    q_mean = mmread("./out/ex6_1/ex6_1_q_reward_mean.mtx")

    rewards = [
        (re_mean, None, None, None, "Roth-Erev"),
        (q_mean, None, None, None, "Q-Learning"),
        (sre_mean, None, None, None, "Stateful RE")
    ]
    figure()
    plot_agents(rewards, r"Reward (\verb+$+)", agents=[0, 3],
                fmt=["w^", "wo", "kp"])

    if tex:
        if paper:
            subplots_adjust(bottom=0.07, top=0.94, hspace=0.25)
        else:
            subplots_adjust(hspace=0.3)
        savefig('./out/ex6_1/fig6_1.pdf')
    else:
        savefig('./out/ex6_1/fig6_1.png')
Example #43
0
def plot6_3():
    if paper:
        fig_width = 3.0  # width in inches
        fig_height = 4.0  # height in inches
        params = {
            'axes.titlesize': 8,
            'axes.labelsize': 6,
            'text.fontsize': 6,
            'legend.fontsize': 6,
            'xtick.labelsize': 6,
            'ytick.labelsize': 6,
            'figure.figsize': [fig_width, fig_height]
        }
        rcParams.update(params)
    else:
        fig_width = 6.15  # width in inches
        fig_height = 5.0  # height in inches
        params = {'figure.figsize': [fig_width, fig_height]}
        rcParams.update(params)

    q_mean = mmread("./out/ex6_3/ex6_3_q_reward_mean.mtx")
    enac_mean = mmread("./out/ex6_3/ex6_3_enac_reward_mean.mtx")

    rewards = [(q_mean, None, None, None, "Q-Learning"),
               (enac_mean, None, None, None, "ENAC")]
    figure()
    plot_agents(rewards, r"Reward (\verb+$+)", agents=[0, 3], fmt=["wo", "kv"])

    subplots_adjust(hspace=0.3)

    if tex:
        if paper:
            subplots_adjust(bottom=0.07, top=0.94, hspace=0.25)
        else:
            subplots_adjust(hspace=0.3)
        savefig('./out/ex6_3/fig6_3.pdf')
    else:
        savefig('./out/ex6_3/fig6_3.png')
Example #44
0
def plot6_3():
    if paper:
        fig_width = 3.0 # width in inches
        fig_height = 4.0 # height in inches
        params = {'axes.titlesize': 8,
                  'axes.labelsize': 6,
                  'text.fontsize': 6,
                  'legend.fontsize': 6,
                  'xtick.labelsize': 6,
                  'ytick.labelsize': 6,
                  'figure.figsize': [fig_width, fig_height]}
        rcParams.update(params)
    else:
        fig_width = 6.15 # width in inches
        fig_height = 5.0 # height in inches
        params = {'figure.figsize': [fig_width, fig_height]}
        rcParams.update(params)

    q_mean = mmread("./out/ex6_3/ex6_3_q_reward_mean.mtx")
    enac_mean = mmread("./out/ex6_3/ex6_3_enac_reward_mean.mtx")

    rewards = [
        (q_mean, None, None, None, "Q-Learning"),
        (enac_mean, None, None, None, "ENAC")
    ]
    figure()
    plot_agents(rewards, r"Reward (\verb+$+)", agents=[0, 3], fmt=["wo", "kv"])

    subplots_adjust(hspace=0.3)

    if tex:
        if paper:
            subplots_adjust(bottom=0.07, top=0.94, hspace=0.25)
        else:
            subplots_adjust(hspace=0.3)
        savefig('./out/ex6_3/fig6_3.pdf')
    else:
        savefig('./out/ex6_3/fig6_3.png')
Example #45
0
def SetForPng(proport=0.75, fig_width_pt=455.24, dpi=150, xylabel_fs=9, leg_fs=8, text_fs=9, xtick_fs=7, ytick_fs=7):
    """
    Set figure proportions
    ======================
    """
    inches_per_pt = 1.0 / 72.27  # Convert pt to inch
    fig_width = fig_width_pt * inches_per_pt  # width in inches
    fig_height = fig_width * proport  # height in inches
    fig_size = [fig_width, fig_height]
    params = {
        "axes.labelsize": xylabel_fs,
        "font.size": text_fs,
        "legend.fontsize": leg_fs,
        "xtick.labelsize": xtick_fs,
        "ytick.labelsize": ytick_fs,
        "figure.figsize": fig_size,
        "savefig.dpi": dpi,
    }
    # utl.Ff(&bb, "SetFontSize(%s)\n", args)
    # utl.Ff(&bb, "rcParams.update({'savefig.dpi':%d})\n", dpi)
    MPLclose()
    rcdefaults()
    rcParams.update(params)
Example #46
0
def PlotProbBins(X, P):
    """
    PlotProbBins plots probabilities bins
     X -- population
     P -- probabilities
    """
    rcParams.update({'figure.figsize':[800/72.27,200/72.27]})
    x0, Tk = 0.0, [0.0]
    for i in range(len(X)):
        gca().add_patch(Rectangle([x0, 0], P[i], 0.2, color='#d5e7ed', ec='black', clip_on=0))
        ha = 'center'
        if i==len(X)-1: ha = 'left' # last one
        text(x0+P[i]/2.0, 0.1, '%.1f'%X[i], ha=ha)
        x0 += P[i]
        Tk.append(x0)
    xticks(Tk, ['%.2f'%v for v in Tk])
    axis('equal')
    gca().get_yaxis().set_visible(False)
    for dir in ['left', 'right', 'top']:
        gca().spines[dir].set_visible(False)
    xlabel('cumulated probability')
    grid()
    axis([0, 1, 0, 0.2])
Example #47
0
def SetForEps(
    proport=0.75,
    fig_width_pt=455.24,
    xylabel_fs=9,
    leg_fs=8,
    text_fs=9,
    xtick_fs=7,
    ytick_fs=7,
    text_usetex=True,
    mplclose=True,
):
    """
    Set figure proportions
    ======================
    """
    # fig_width_pt = 455.24411                  # Get this from LaTeX using \showthe\columnwidth
    inches_per_pt = 1.0 / 72.27  # Convert pt to inch
    fig_width = fig_width_pt * inches_per_pt  # width in inches
    fig_height = fig_width * proport  # height in inches
    fig_size = [fig_width, fig_height]
    # params = {'mathtext.fontset':'stix', # 'cm', 'stix', 'stixsans', 'custom'
    params = {
        "backend": "ps",
        "axes.labelsize": xylabel_fs,
        "font.size": text_fs,
        "legend.fontsize": leg_fs,
        "xtick.labelsize": xtick_fs,
        "ytick.labelsize": ytick_fs,
        "text.usetex": text_usetex,  # very IMPORTANT to avoid Type 3 fonts
        "ps.useafm": True,  # very IMPORTANT to avoid Type 3 fonts
        "pdf.use14corefonts": True,  # very IMPORTANT to avoid Type 3 fonts
        "figure.figsize": fig_size,
    }
    if mplclose:
        MPLclose()
    rcdefaults()
    rcParams.update(params)
Example #48
0
    def __init__(self, tm):
        self.tm = tm
        self.overlaps = []

        import matplotlib.pyplot as plt
        self.plt = plt
        import matplotlib.cm as cm
        self.cm = cm

        from pylab import rcParams
        rcParams.update({'figure.figsize': (6, 9)})
        rcParams.update({'figure.autolayout': True})
        rcParams.update({'figure.facecolor': 'white'})
Example #49
0
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import rcParams
import numpy as np
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
rcParams.update({'figure.autolayout': True})

data = pd.read_csv("./datasets/telecom churn.csv")

data.head()


label = data["Churn"].value_counts(sort=True).index.tolist()

size = data["Churn"].value_counts(sort=True)
'''
                    ./results/plt-churn_percentage.png
'''
plt.pie(size, autopct="%1.1f%%", shadow=True, startangle=55, labels=label, explode=(0.1, 0.1))
plt.title("Churn%")
plt.show()

# dropping irrelevant columns
data.drop(['customerID'], axis=1, inplace=True)
data.isnull().any() # all False indicating no null values

data['TotalCharges'] = pd.to_numeric(data['TotalCharges']) # error
Example #50
0
                        type=str)
    parser.add_argument('-w', '--window', type=int, default=100)
    parser.add_argument('-n', '--num', type=int, default=None)
    parser.add_argument('-t', '--training-hide', type=int, nargs='+')
    parser.add_argument('-g', '--graph-labels', type=str, nargs='+')
    parser.add_argument('-s', '--size-of-line', type=float, nargs='+')
    parser.add_argument('-l', '--legend-position', type=int, default=4)
    parser.add_argument('-f', '--full', action='store_true')
    parser.add_argument('-o', '--output', type=str, default=None)

    suite = PyExperimentSuite()
    args = parser.parse_args()

    from pylab import rcParams

    rcParams.update({'figure.autolayout': True})
    rcParams.update({'figure.facecolor': 'white'})
    rcParams.update({'ytick.labelsize': 8})
    rcParams.update({'figure.figsize': (12, 6)})
    rcParams.update({'pdf.fonttype': 42})

    experiments = args.experiments

    for i, experiment in enumerate(experiments):
        iteration = suite.get_history(experiment, 0, 'iteration')
        predictions = suite.get_history(experiment, 0, 'predictions')
        truth = suite.get_history(experiment, 0, 'truth')
        train = suite.get_history(experiment, 0, 'train')

        resets = None if args.full else suite.get_history(
            experiment, 0, 'reset')
Example #51
0
from __future__ import print_function, division
from nilmtk import DataSet, TimeFrame, MeterGroup
import plot_config
import seaborn as sns
from matplotlib.dates import DateFormatter, HourLocator
from datetime import timedelta
import matplotlib.pyplot as plt
import pytz
import pandas as pd
from os.path import join

from pylab import rcParams

rcParams.update({'figure.figsize': plot_config._mm_to_inches(180, 100)})

UNIT = 'kW'

dataset = DataSet('/data/mine/vadeec/merged/ukdale.h5')
TZ_STRING = dataset.metadata['timezone']
TZ = pytz.timezone(TZ_STRING)
elec = dataset.buildings[1].elec
submeters = elec.meters_directly_downstream_of_mains()

# Select appliances used in top K plot
APPLIANCES = [
    'fridge freezer', 'HTPC', 'dish washer', 'washer dryer', 'kettle'
]
selected_meters = [submeters[appliance] for appliance in APPLIANCES]
remainder = []
for meter in submeters.meters:
    for appliance in APPLIANCES:
Example #52
0
        plt.axis('off')
        # Ground Truth
        plt.subplot(1, 3, 2)
        plt.imshow(a_i.reshape(patch_size,patch_size),  cmap='Greys')
        plt.axis('off')
        # Denoised Image
        plt.subplot(1, 3, 3)
        plt.imshow(output_any_image.reshape(patch_size,patch_size),  cmap='Greys')
        plt.axis('off')
        plt.show()    
        '''
    if epoch%100 == 0 :
        print('Epoch', epoch, '/', hm_epochs, 'loss:',epoch_loss)


x = range(5000,5000*(len(PSNR_0)+1),5000)
y0 = PSNR_0
y1 = PSNR_1

rcParams['figure.figsize'] = 8,8
rcParams.update({'font.size': 12})

plt.plot(x,y0,'b',label='Lena',marker='^')
plt.plot(x,y1,'r',label='Man',marker='D')
plt.xlabel('Epochs')
plt.ylabel('PSNR(dB)')
plt.title('MLP(multilayer perceptron)')
plt.legend(loc='upper right')
plt.show()

Example #53
0
def plot_bar(data_fh, target, xlabel, ylabel, zlabel, title, x_label, y_label,
             x_order, y_order, fig_width, fig_height, fontsize,
             xlabel_rotation, category, colours):
    '''
    xlabel: groups on x axis
    ylabel: colours
  '''
    logging.info('starting...')

    import matplotlib.style
    matplotlib.style.use('seaborn')

    included = total = 0
    results = {}
    xvals = set()
    yvals = set()
    max_zval = 0.0
    categories = {}
    for row in csv.DictReader(data_fh, delimiter='\t'):
        try:
            included += 1
            xval = row[xlabel]  # group axis value
            yval = row[ylabel]  # sub-group axis value
            xvals.add(xval)
            yvals.add(yval)
            zval = float(row[zlabel])
            max_zval = max(max_zval, zval)
            xy = '{},{}'.format(xval, yval)
            results[xy] = zval
            logging.debug('Added %s = %f', xy, zval)
            if category is not None:
                categories[xy] = row[category]
        except:
            logging.debug('Failed to include %s', row)

        total += 1

    logging.info('finished reading %i of %i records with max_zval %.2f',
                 included, total, max_zval)

    if len(results) == 0:
        logging.warn('No data to plot')
        return

    if x_order is None:
        xvals = sorted(list(xvals))  # groups
    else:
        xvals = x_order  # groups
    if y_order is None:
        yvals = sorted(list(yvals))  # sub-groups
    else:
        yvals = y_order

    logging.debug('xvals %s yvals %s', xvals, yvals)

    #fig, ax = plt.subplots()

    #fig_width = min(18, max(9, len(xvals) * len(yvals)))
    fig = plt.figure(figsize=(fig_width, fig_height))
    rcParams.update({'font.size': fontsize})
    ax = fig.add_subplot(111)

    width = fig_width / len(xvals) / len(yvals)
    ind = np.arange(len(xvals)) * fig_width / len(
        xvals)  # the x locations for the groups
    logging.info('ind is %s, width is %f fig_width is %f', ind, width,
                 fig_width)

    for idx in range(len(yvals)):  # each yval
        offset = idx * width * 0.9 - (len(yvals) - 1) * width / 2
        vals = [results['{},{}'.format(x, yvals[idx])]
                for x in xvals]  # each xval with that yval
        logging.debug('adding values %s for %s at %s', vals, yvals[idx],
                      ind + offset)

        if category is None:
            rects = ax.bar(ind + offset, vals, width * 0.85, label=yvals[idx])
        else:
            rects = ax.bar(ind + offset, vals, width * 0.85)

        for rect, val in zip(rects, xvals):
            height = rect.get_height()
            if height < 0.01:
                annot = '{:.3e}'.format(height)
            else:
                annot = '{:.2f}'.format(height)
            ax.annotate(
                annot,
                xy=(rect.get_x() + rect.get_width() / 2, height),
                xytext=(0, 3),  # use 3 points offset
                textcoords="offset points",  # in both directions
                ha='center',
                va='bottom')

            if category is not None:
                label = '{} {}'.format(
                    categories['{},{}'.format(val, yvals[idx])], yvals[idx])
                rect.set_label(label)
                if colours is not None:
                    for colour in colours:
                        cat, col = colour.split('=')
                        if cat == label:
                            rect.set_color(col)

    # Add some text for labels, title and custom x-axis tick labels, etc.
    if y_label is not None:
        ax.set_ylabel(y_label)
    if x_label is not None:
        ax.set_xlabel(x_label)
    ax.set_title(title)
    ax.set_xticks(ind)
    ax.set_xticklabels(xvals, rotation=xlabel_rotation)
    #ax.legend(loc='upper right')

    # place legend at right based on https://stackoverflow.com/questions/10101700/moving-matplotlib-legend-outside-of-the-axis-makes-it-cutoff-by-the-figure-box/10154763#10154763
    handles, labels = ax.get_legend_handles_labels()
    labels_seen = set()
    labels_u = []
    handles_u = []
    for handle, label in sorted(zip(handles, labels),
                                key=lambda pair: pair[1]):
        if label in labels_seen:
            continue
        labels_seen.add(label)
        labels_u.append(label)
        handles_u.append(handle)
    lgd = ax.legend(handles_u,
                    labels_u,
                    loc='upper left',
                    bbox_to_anchor=(1.01, 1.0),
                    borderaxespad=0)
    lgd.get_frame().set_edgecolor('#000000')

    #fig = plt.figure(figsize=(figsize, 1 + int(figsize * len(yvals) / len(xvals))))
    #ax = fig.add_subplot(111)

    logging.info('done processing %i of %i', included, total)
    plt.tight_layout()
    plt.savefig(target)
    matplotlib.pyplot.close('all')
Example #54
0
def plot(title,
         results,
         sort_by='total',
         fract_of=False,
         y_label=False,
         num_to_plot=7,
         significance_level=0.05,
         multiplier=100,
         yearspan=False,
         proj63=5,
         justyears=False,
         csvmake=False,
         x_label=False,
         legend_p=False,
         legend_totals=False,
         log=False,
         figsize=11,
         save=False,
         only_below_p=False,
         skip63=False,
         projection=True):
    """
    Visualise interrogator() results, optionally generating a csv as well.

    Parameters
    ----------

    title : string
        Chart title
    results : list
        interrogator() results or totals (deaults to results)
    sort_by : string
        'total': sort by most frequent
        'increase': calculate linear regression, sort by steepest up slope
        'decrease': calculate linear regression, sort by steepest down slope 
        'static': calculate linear regression, sort by least slope
    fract_of : list
        measure results as a fraction (default: as a percentage) of this list.
        usually, use interrogator() totals
    multiplier : int
        mutliply results list before dividing by fract_of list
        Default is 100 (for percentage), can use 1 for ratios
    y_label : string
        text for y-axis label (default is 'Absolute frequency'/'Percentage') 
    X_label : string
        text for x-axis label (default is 'Group'/'Year')
    num_to_plot : int
        How many top entries to show
    significance_level : float
        If using sort_by, set the p threshold (default 0.05)
    only_below_p : Boolean
        Do not plot any results above p value
    yearspan : list with two ints
        Get only results between the specified ints
    justyears : list of ints
        Get only results from the listed subcorpora
    csvmake : True/False/string
        Generate a CSV of plotted and all results with string as filename
        If True, 'title' string is used
    legend_totals : Boolean
        Show total frequency of each result, or overall percentage if fract_of
    legend_p : Boolean
        Show p-value for slope when using sort_by
    log : False/'x'/'y'/'x, y'
        Use logarithmic axes
    figsize = int
        Size of image
    save = True/False/string
        Generate save image with string as filename
        If True, 'title' string is used for name

    NYT-only parameters
    -----
    skip63 : boolean
        Skip 1963 results (for NYT investigation)
    projection : boolean
        Project 1963/2014 results (for NYT investigation)
    proj63 : int
        The amount to project 1963 results by

    Example
    -----
    from corpkit import interrogator, plotter
    corpus = 'path/to/corpus'
    adjectives = interrogator(corpus, 'words', r'/JJ.?/ < __')
    plotter('Most common adjectives', adjectives.results, fract_of = adjectives.totals,
            csvmake = True, legend_totals = True)

    """

    import os
    import warnings
    import copy
    from time import localtime, strftime

    import matplotlib.pyplot as plt
    from matplotlib import rc
    from matplotlib.ticker import MaxNLocator, ScalarFormatter
    import pylab
    from pylab import rcParams
    try:
        get_ipython().getoutput()
    except TypeError:
        have_ipython = True
    except NameError:
        import subprocess
        have_ipython = False
    try:
        from IPython.display import display, clear_output
    except ImportError:
        pass
    from corpkit.query import check_dit, check_pytex, check_tex
    from corpkit.edit import resorter, mather

    # setup:

    # size:
    rcParams['figure.figsize'] = figsize, figsize / 2

    #font
    rcParams.update({'font.size':
                     (figsize / 2) + 7})  # half your size plus seven

    # check what we're doing here.
    have_python_tex = check_pytex()
    on_cloud = check_dit()
    have_tex = check_tex(have_ipython=have_ipython)

    def skipper(interrogator_list):
        """Takes a list and returns a version without 1963"""
        skipped = []
        skipped.append(interrogator_list[0])  # append word
        for item in interrogator_list[1:]:
            if type(item) != unicode and type(item) != str and item[0] != 1963:
                skipped.append(item)
        return skipped

    def yearskipper(interrogator_list, justyears):
        """Takes a list and returns only results from the years listed in justyears"""
        skipped = []
        skipped.append(interrogator_list[0])  # append word
        for item in interrogator_list[1:]:
            if type(item) != unicode and type(item) != str:
                for year in justyears:
                    if item[0] == year:
                        skipped.append(item)
        return skipped

    def yearspanner(interrogator_list, yearspan):
        """Takes a list and returns results from between the first and last year in yearspan"""

        skipped = [interrogator_list[0]]  # append word
        for item in interrogator_list[1:]:
            if type(item) != unicode and type(item) != str:
                if item[0] >= yearspan[0]:
                    if item[0] <= yearspan[-1] + 1:
                        skipped.append(item)
        return skipped

    def projector(interrogator_list):
        """Takes a list and returns a version with projections"""
        projected = []
        projected.append(interrogator_list[0])  # append word
        for item in interrogator_list[1:]:
            if type(item) != str and type(item) != str and item[0] == 1963:
                newtotal = item[1] * proj63
                datum = [item[0], newtotal]
                projected.append(datum)
            elif type(item) != str and type(item) != str and item[0] == 2014:
                newtotal = item[1] * 1.37
                datum = [item[0], newtotal]
                projected.append(datum)
            else:
                projected.append(item)
        return projected

    def csvmaker(csvdata, csvalldata, csvmake):
        """Takes whatever ended up getting plotted and puts it into a csv file"""
        # now that I know about Pandas, I could probably make this much less painful.
        csv = []
        yearlist = []
        # get list of years
        for entry in csvdata[0]:
            if type(entry) == list:
                yearlist.append(str(entry[0]))
        # make first line
        csv.append(title)
        # make the second line
        years = ',' + ','.join(yearlist)
        csv.append(years)
        # for each word
        for entry in csvdata:
            csvline = []
            csvcounts = []
            csvline.append(entry[0])  # append word
            for part in entry[1:]:
                csvcounts.append(str(part[1]))  # append just the count
            counts = ','.join(csvcounts)
            csvline.append(counts)
            line = ','.join(csvline)
            csv.append(line)
        csv = '\n'.join(csv)
        # now do all data
        csvall = []
        yearlist = []
        # get list of years
        for entry in csvalldata[0]:
            if type(entry) == list:
                yearlist.append(str(entry[0]))
        # make first line
        csvall.append(title)
        # make the second line
        years = ',' + ','.join(yearlist)
        csvall.append(years)
        # for each word
        for entry in csvalldata:
            csvallline = []
            csvallcounts = []
            csvallline.append(entry[0])  # append word
            for part in entry[1:]:
                csvallcounts.append(str(part[1]))  # append just the count
            counts = ','.join(csvallcounts)
            csvallline.append(counts)
            line = ','.join(csvallline)
            csvall.append(line)
        csvall = '\n'.join(csvall)
        # write the csvall file?
        if os.path.isfile(csvmake):
            raise ValueError(
                "CSV error: %s already exists in current directory. \
                    Move it, delete it, or change the name of the new .csv file."
                % csvmake)
        try:
            fo = open(csvmake, "w")
        except IOError:
            print "Error writing CSV file."
        fo.write('Plotted results:\n'.encode("UTF-8"))
        fo.write(csv.encode("UTF-8"))
        fo.write('\n\nAll results:\n'.encode("UTF-8"))
        fo.write(csvall.encode("UTF-8"))
        fo.close()
        time = strftime("%H:%M:%S", localtime())
        print time + ": " + csvmake + " written to currect directory."

    ##################################################################

    # check for tex and use it if it's there
    if have_tex:
        rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
        rc('text', usetex=True)

    #image directory
    if have_python_tex:
        imagefolder = '../images'
    else:
        imagefolder = 'images'

    # Use .results branch if branch is unspecified
    if isinstance(results, tuple) is True:
        warnings.warn('\nNo branch of results selected. Using .results ... ')
        results = results.results
    if only_below_p:
        if sort_by == 'static':
            warnings.warn(
                '\nStatic trajectories will confirm the null hypothesis, so it might '
                +
                'not be helpful to use both the static and only_below_p options together.'
            )
        if sort_by == 'total' or sort_by == 'name':
            warnings.warn(
                "\nP value has not been calculated. No entries will be excluded"
            )

    # cut short to save time if later results aren't useful
    if csvmake or sort_by != 'total':
        cutoff = len(results)
    else:
        cutoff = num_to_plot

    # if plotting one entry/a totals list, wrap it in another list
    if type(results[0]) == unicode or type(results[0]) == str:
        legend = False
        alldata = [copy.deepcopy(results)][:cutoff]
        num_to_plot = 1
    else:
        legend = True
        alldata = copy.deepcopy(results[:cutoff])

    # determine if no subcorpora and thus barchart
    if len(results[0]) == 3 or len(results[0]) == 4:
        barchart = True
    else:
        barchart = False

    # if no x_label, guess 'year' or 'group'
    if x_label:
        x_lab = x_label
    else:
        if not barchart:
            check_x_axis = alldata[0]  # get first entry
            check_x_axis = check_x_axis[
                1]  # get second entry of first entry (year, count)
            if 1500 < check_x_axis[0] < 2050:
                x_lab = 'Year'
            else:
                x_lab = 'Group'
        else:
            x_lab = False

    # select totals if no branch selected
    if fract_of:
        if isinstance(fract_of, tuple) is True:
            warnings.warn(
                '\nNo branch of fract_of selected. Using .totals ... ')
            fract_of = fract_of.totals
        # copy this, to be safe!
        totals = copy.deepcopy(fract_of)

        #use mather to make percentage results
        fractdata = []
        for entry in alldata:
            fractdata.append(mather(entry, '%', totals, multiplier=multiplier))
        alldata = copy.deepcopy(fractdata)

    # sort_by with resorter
    if sort_by != 'total':
        do_stats = True
        alldata = resorter(alldata,
                           sort_by=sort_by,
                           keep_stats=True,
                           only_below_p=only_below_p,
                           significance_level=significance_level,
                           skip63=skip63)
    else:
        do_stats = False
    csvdata = []
    csvalldata = []
    final = []
    colours = [
        "#1f78b4", "#33a02c", "#e31a1c", "#ff7f00", "#6a3d9a", "#a6cee3",
        "#b2df8a", "#fb9a99", "#fdbf6f", "#cab2d6"
    ]
    c = 0

    if num_to_plot > len(alldata):
        warnings.warn(
            "There are not %d entries to show.\nPlotting all %d results..." %
            (num_to_plot, len(alldata)))

    if not csvmake:
        cutoff = num_to_plot

    if not barchart:
        for index, entry in enumerate(alldata[:cutoff]):
            # run called processes
            if skip63:
                entry = skipper(entry)
            if yearspan:
                entry = yearspanner(entry, yearspan)
            if justyears:
                entry = yearskipper(entry, justyears)
            if projection:
                if not fract_of:
                    entry = projector(entry)
            # get word
            word = entry[0]
            if do_stats:
                pval = entry[-1][3]
                p_short = "%.4f" % pval
                p_string = ' (p=%s)' % p_short
                # remove stats, we're done with them.
                entry.pop()
            # get totals ... horrible code
            total = 0
            if fract_of:
                if entry[-1][0] == 'Total':
                    num = entry[-1][1]
                    total = "%.2f" % num
                    #total = str(float(entry[-1][1]))[:5]
                totalstring = ' (' + str(total) + '\%)'
            else:
                if entry[-1][0] == 'Total':
                    total = entry[-1][1]
                totalstring = ' (n=%d)' % total

            entry.pop()  # get rid of total. good or bad?
            csvalldata.append(entry)

            if index < num_to_plot:
                csvdata.append(entry)
                toplot = []
                xvalsbelow = []
                yvalsbelow = []
                xvalsabove = []
                yvalsabove = []
                d = 1  # first tuple, maybe not very stable
                tups = len(
                    entry) - 2  # all tuples minus 2 (to skip totals tuple)
                for _ in range(tups):
                    firstpart = entry[d]  # first tuple
                    firstyear = firstpart[0]
                    nextpart = entry[d + 1]
                    nextyear = nextpart[0]
                    if nextyear - firstyear > 50:  # change to 1 for nyt
                        xvalsbelow.append(firstpart[0])
                        yvalsbelow.append(firstpart[1])
                        xvalsbelow.append(nextpart[0])
                        yvalsbelow.append(nextpart[1])
                    else:
                        xvalsabove.append(firstpart[0])
                        yvalsabove.append(firstpart[1])
                        xvalsabove.append(nextpart[0])
                        yvalsabove.append(nextpart[1])
                    d += 1
                if csvmake:  # append exactly what was plotted...
                    csvdata.append(entry)

                # do actual plotting
                plt.plot(xvalsbelow, yvalsbelow, '--', color=colours[c])
                plt.plot(xvalsabove,
                         yvalsabove,
                         '-',
                         label=word,
                         color=colours[c])
                plt.plot(xvalsabove, yvalsabove, '.',
                         color=colours[c])  # delete for nyt

                if c == 8:
                    c = 0  # unpythonic
                c += 1

            # old way to plot everything at once
            #plt.plot(*zip(*toplot), label=word) # this is other projects...

        #make legend
        if legend:
            lgd = plt.legend(bbox_to_anchor=(1.05, 1),
                             loc=2,
                             borderaxespad=0.,
                             fancybox=True,
                             framealpha=0.5)

    elif barchart:
        rcParams['figure.figsize'] = figsize, figsize / 2
        cutoff = len(alldata)
        import numpy as np
        scores = [entry[1][1] for entry in alldata[:cutoff]]
        ind = np.arange(cutoff)  # the x locations for the groups
        width = 0.35  # the width of the bars

        fig, ax = plt.subplots()
        rects1 = ax.bar(ind, scores, width, color="#1f78b4")

        if len(results[0]) == 4:
            compscores = [entry[2][1] for entry in alldata[:cutoff]]
            rects2 = ax.bar(ind + width, compscores, width, color="#33a02c")

        # add some text for labels, title and axes ticks

        ax.set_xticks(ind + width)

        # get labels
        labels = [entry[0] for entry in alldata[:cutoff]]

        longest = len(max(labels, key=len))
        if longest > 7:
            if figsize < 20:
                if num_to_plot > 6:
                    ax.set_xticklabels(labels, rotation=45)
        else:
            ax.set_xticklabels(labels)

        # rotate the labels if they're long:

        #def autolabel(rects):
        # attach some text labels
        #for rect in rects:
        #height = rect.get_height()
        #ax.text(rect.get_x()+rect.get_width()/2., 1.0*height, '%d'%int(height),
        #ha='center', va='bottom')

        #autolabel(rects1)
        #if len(results[0]) == 4:
        #autolabel(rects2)
        legend_labels = [alldata[0][1][0], alldata[0][2][0]]
        ax.legend((rects1[0], rects2[0]), legend_labels)

    # make axis labels
    if x_lab:
        plt.xlabel(x_lab)

    if not y_label:
        #print "Warning: no name given for y-axis. Using default."
        if fract_of:
            y_label = 'Percentage'
        if not fract_of:
            y_label = 'Total frequency'
    plt.ylabel(y_label)
    pylab.title(title)

    if not barchart:
        plt.gca().get_xaxis().set_major_locator(MaxNLocator(integer=True))

        if log == 'x':
            plt.xscale('log')
            plt.gca().get_xaxis().set_major_formatter(ScalarFormatter())
        elif log == 'y':
            plt.yscale('log')
            plt.gca().get_yaxis().set_major_formatter(ScalarFormatter())
        elif log == 'x, y':
            plt.xscale('log')
            plt.gca().get_xaxis().set_major_formatter(ScalarFormatter())
            plt.yscale('log')
            plt.gca().get_yaxis().set_major_formatter(ScalarFormatter())
        else:
            plt.ticklabel_format(useOffset=False, axis='x', style='plain')
    plt.grid()
    fig1 = plt.gcf()
    if not have_python_tex:
        plt.show()

    def urlify(s):
        import re
        s = s.lower()
        s = re.sub(r"[^\w\s]", '', s)
        s = re.sub(r"\s+", '-', s)
        return s

    if save:
        if type(save) == str:
            savename = os.path.join(imagefolder, urlify(save) + '.png')
        else:
            savename = os.path.join(imagefolder, urlify(title) + '.png')
        if legend and not barchart:
            fig1.savefig(savename,
                         bbox_extra_artists=(lgd, ),
                         bbox_inches='tight',
                         dpi=150,
                         transparent=True)
        else:
            fig1.savefig(savename, dpi=150, transparent=True)
        time = strftime("%H:%M:%S", localtime())
        if os.path.isfile(savename):
            print time + ": " + savename + " created."
        else:
            raise ValueError("Error making %s." % savename)
    if csvmake:
        if type(csvmake) == bool:
            csvmake = urlify(title) + '.csv'
        csvmaker(csvdata, csvalldata, csvmake)
Example #55
0
def plot6_2():
    if paper:
        fig_width = 3.0  # width in inches
        fig_height = 5.5  # height in inches
        params = {
            'axes.titlesize': 6,
            'axes.labelsize': 6,
            'text.fontsize': 6,
            'legend.fontsize': 5,
            'xtick.labelsize': 6,
            'ytick.labelsize': 6,
            'figure.figsize': [fig_width, fig_height]
        }
        rcParams.update(params)

    q1 = mmread("./out/ex6_2/ex6_2-1_q_reward_mean.mtx")
    reinforce1 = mmread("./out/ex6_2/ex6_2-1_reinforce_reward_mean.mtx")
    enac1 = mmread("./out/ex6_2/ex6_2-1_enac_reward_mean.mtx")

    #    q2 = mmread("./out/ex6_2/ex6_2-2_q_reward_mean.mtx")
    reinforce2 = mmread("./out/ex6_2/ex6_2-2_reinforce_reward_mean.mtx")
    enac2 = mmread("./out/ex6_2/ex6_2-2_enac_reward_mean.mtx")

    maxSteps = 24
    nplots = 4
    fmt = ["wo", "ks", "kv"]

    x = arange(0.0, maxSteps, 1.0)

    def plot62(results, i, n):
        ax = subplot(nplots, 1, n)
        if paper:
            msize = 3
        else:
            msize = 5

        for k, (r, lab) in enumerate(results):
            plot(x,
                 r[i, :],
                 fmt[k],
                 linestyle="None",
                 markersize=msize,
                 label=lab)

        ax.ticklabel_format(style='sci', scilimits=(0, 0), axis='y')

        xlim((0, 23))
        if paper:
            locator = FixedLocator(range(0, 24, 2))
        else:
            locator = FixedLocator(range(0, 24))
        ax.xaxis.set_major_locator(locator)  #minor x-axis ticks

        ylabel(r"Reward (\verb+$+)")

        l = legend(loc="upper left")
        l.get_frame().set_linewidth(0.5)

    results1 = [(q1, "Q-learning"), (reinforce1, "REINFORCE"), (enac1, "ENAC")]
    results2 = [(q1, "Q-learning"), (reinforce2, "REINFORCE"), (enac2, "ENAC")]

    figure()
    plot62(results1, i=1, n=1)
    title("Agent 1 (demand forecast only)")
    plot62(results2, i=1, n=2)
    title("Agent 1 (demand and bus voltage)")
    #    xlabel("Hour")
    #    if tex:
    #        savefig('./out/ex6_2/fig6_2_agent1.pdf')

    #    figure()
    plot62(results1, i=3, n=3)
    title("Agent 4 (demand forecast only)")
    plot62(results2, i=3, n=4)
    title("Agent 4 (demand and bus voltage)")
    xlabel("Hour")
    #    if tex:
    #        savefig('./out/ex6_2/fig6_2_agent4.pdf')

    subplots_adjust(hspace=0.3)

    if tex:
        if paper:
            subplots_adjust(bottom=0.05, top=0.96)
        savefig('./out/ex6_2/fig6_2.pdf')
    else:
        savefig('./out/ex6_2/fig6_2.png')
Example #56
0

FONTSIZE = 8
params = {
    'figure.figsize':
    _mm_to_inches(180, 80),  # 180 or 88mm wide for Scientific Data
    'axes.labelsize': FONTSIZE,  # FONTSIZE for x and y labels (was FONTSIZE)
    'axes.titlesize': FONTSIZE,
    'text.fontsize': FONTSIZE,  # was FONTSIZE
    'legend.fontsize': FONTSIZE,  # was FONTSIZE
    'xtick.labelsize': FONTSIZE,
    'ytick.labelsize': FONTSIZE,
    'font.family': 'Bitstream Vera Sans'
}

rcParams.update(params)


def format_axes(ax, tick_size=4):
    for axis in [ax.xaxis, ax.yaxis]:
        axis.set_tick_params(direction='out', color='k', size=tick_size)

    return ax


FIG_DIR = expanduser(
    "~/Dropbox/MyWork/imperial/PhD/writing/papers/scientific-data-2014/figures"
)

BLUE = (0.2980392156862745, 0.4470588235294118, 0.6901960784313725)
GREEN = (0.3333333333333333, 0.6588235294117647, 0.40784313725490196)
Example #57
0
    },
    inplace=True,
)
data.head()

# In[154]:

data.info()

# In[177]:

from pylab import rcParams
from statsmodels.tsa.seasonal import seasonal_decompose

rcParams.update({
    "figure.figsize": (20, 16),
    "font.size": 16,
})

idx = pd.Index(sm.tsa.datetools.dates_from_range("1749", "2017"))

result = seasonal_decompose(data.sunspots[idx], model="additive")
result.plot()

# In[190]:

from pandas.plotting import autocorrelation_plot

rcParams.update({"figure.figsize": (20, 8)})

autocorrelation_plot(data.sunspots)
Example #58
0
def plot_seg(data_fh,
             target,
             xlabel,
             ylabel,
             lower,
             mean,
             upper,
             title,
             x_label,
             y_label,
             x_order,
             y_order,
             fig_width,
             fig_height,
             fontsize,
             x_label_rotation='vertical',
             no_legend=False,
             linewidth=1,
             dpi=300,
             separator=False):
    '''
    xlabel: category
    ylabel: sub-category
    zlabel: 
  '''
    logging.info('starting...')

    import matplotlib.style
    matplotlib.style.use('seaborn')
    rcParams.update({'lines.markeredgewidth': 0.1})  # seaborn removes fliers

    included = total = 0
    results = collections.defaultdict(dict)
    xvals = set()
    yvals = set()
    for row in csv.DictReader(data_fh, delimiter='\t'):
        try:
            included += 1
            xval = row[xlabel]  # group axis name
            yval = row[ylabel]  # sub-group axis name
            results[xval][yval] = (float(row[mean]), float(row[lower]),
                                   float(row[upper]))
            xvals.add(xval)
            yvals.add(yval)
        except:
            logging.warn('Failed to include %s', row)

        total += 1

    logging.info('finished reading %i of %i records', included, total)
    logging.debug('xvals %s yvals %s results %s', xvals, yvals, results)

    if len(results) == 0:
        logging.warn('No data to plot')
        return

    logging.debug('xvals %s yvals %s', xvals, yvals)

    #fig, ax = plt.subplots()

    #fig_width = min(18, max(6, len(xvals) * len(yvals)))
    #fig = plt.figure(figsize=(fig_width, fig_width * 0.7))
    rcParams.update({'font.size': fontsize})
    fig = plt.figure(figsize=(fig_width, fig_height))
    plt.rc('legend', fontsize=fontsize)
    ax = fig.add_subplot(111)
    ax.tick_params(axis='x', labelsize=fontsize)
    ax.tick_params(axis='y', labelsize=fontsize)
    ax.grid(axis='y', linewidth=0)  # no lines on y-axis

    #ax.errorbar(list(xvals), , xerr=errs, fmt='o')
    # do each sub-category with a different color
    for ydx, yval in enumerate(sorted(yvals)):
        xs = []
        ys = []
        ls = []
        us = []
        for xdx, xval in enumerate(sorted(xvals)):
            position = xdx * len(yvals) + ydx
            xs.append(position)
            ys.append(results[xval][yval][0])
            ls.append(results[xval][yval][0] - results[xval][yval][1])
            us.append(results[xval][yval][2] - results[xval][yval][0])
        logging.debug('xs %s ys %s for %i', xs, ys, ydx)
        ax.errorbar(ys, xs, xerr=[ls, us], fmt='o', c=COLORS[ydx], label=yval)

    if separator:
        for x in range(len(xvals) - 1):
            ax.axhline((x + 1) * len(yvals) - 0.5, color='white', linewidth=1)

    labels = sorted(xvals)
    positions = [
        x * len(yvals) + ((len(yvals) - 1) / 2) for x in range(len(xvals))
    ]

    ax.yaxis.set_major_locator(matplotlib.ticker.FixedLocator(positions))
    ax.yaxis.set_major_formatter(matplotlib.ticker.FixedFormatter(labels))
    ax.legend()

    ax.set_title(title)

    #if separator:
    #  for i, x in enumerate(ind[:-1]):
    #    ax.axvline((x + ind[i+1]) / 2, color='white', linewidth=1)
    #    logging.debug('vline at %f', x)

    # Add some text for labels, title and custom x-axis tick labels, etc.
    if y_label is not None:
        ax.set_ylabel(y_label, fontsize=fontsize)
    if x_label is not None:
        ax.set_xlabel(x_label, fontsize=fontsize)
    ax.set_title(title, fontsize=fontsize)

    logging.info('done processing %i of %i. plot at dpi %i', included, total,
                 dpi)
    plt.tight_layout()
    plt.savefig(target, dpi=dpi)
    matplotlib.pyplot.close('all')
import os
import argparse
import csv
import matplotlib.pyplot as plt
from pylab import rcParams

rcParams['pdf.fonttype'] = 42
rcParams['ps.fonttype'] = 42
rcParams.update({'font.size': 44})

BLOCKS_PER_CHUNK = 16
BLOCKS_PER_PLAYER_LOG_LENGTH_UNIT = 150

CAPTION_REPLACEMENTS = {
    "1x1": "Single Server Setting",
    "2x1": "Two Server Setting",
    "3x1": "Three Server Setting",
    "2x2": "Four Server Setting",
    "3x3": "Nine Server Setting"
}


def readPlayerFiles(directory):
    player_movement_info = {}
    for file in os.listdir(directory):
        if file.startswith("player_") and file.endswith("_movement.csv"):
            id = file.split("_")[1]
            movement = {"x": [], "z": []}

            with open(os.path.join(directory, file), 'rt') as csvfile:
                reader = csv.reader(csvfile, delimiter="\t")