コード例 #1
0
def test_pcolormesh_lognorm():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    x = np.abs(np.random.randn(10, 10))
    ppl.pcolormesh(fig, ax, x, norm=LogNorm(vmin=x.min().min(), vmax=x.max().max()))
コード例 #2
0
ファイル: cluster.py プロジェクト: stephentu/vldbtrends
  def add_content(subcluster, content, suffix):
      fig, ax = plt.subplots(1, figsize=(6.5,2.5))
      for childax in ax.get_children():
        if isinstance(childax, mpl.spines.Spine):
          childax.set_color('#aaaaaa')
      for i in ax.get_xticklabels():
        i.set_color('#aaaaaa')
      for i in ax.get_yticklabels():
        i.set_color('#aaaaaa')

      subcluster = sorted(subcluster, key=lambda t: max(t[1:].astype(float)), reverse=True)[:10]
      subcluster = np.array(subcluster)
      words = subcluster[:,0]
      ys = subcluster[:,1:].astype(float)
      mean = [np.mean(ys[:,i]) for i in xrange(ys.shape[1])]
      ys = ys.transpose()
      ax.set_ylim(top=max(10, max(map(max, ys))))

      ppl.plot(ax, xs, ys, alpha=0.3, color="#7777ee")
      ppl.plot(ax, xs, mean, alpha=1, color="black")
      fname = './plots/%s_%s.png' % (conf, suffix)
      fig.savefig(fname, format='png')

      maxes = map(max, ys)
      idx = maxes.index(max(maxes))
      content.append(('', words, fname, idx))
コード例 #3
0
def test_pcolormesh_negative():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, -np.random.uniform(size=(10, 10)),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:])
コード例 #4
0
def test_pcolormesh_other_cmap():
    purple_green = brewer2mpl.get_map('PRGn', 'diverging', 11).mpl_colormap

    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, np.random.randn(10, 10), cmap=purple_green)
コード例 #5
0
ファイル: pick_pts.py プロジェクト: OminiaVincit/bigdata
def plot_days(days):
  nplots = len(days)
  fig, subplots = plt.subplots(nplots, figsize=(10, 50))
  for i, day in enumerate(days):
    subplot = subplots[i]
    plot_day(day, subplot)
  plt.tight_layout()
  plt.savefig('./plots/best.png')
コード例 #6
0
def test_pcolormesh_positive():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(
        fig, ax, np.random.uniform(size=(10, 10)), xticklabels=string.uppercase[:10], yticklabels=string.lowercase[-10:]
    )
コード例 #7
0
def test_pcolormesh_labels():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(
        fig, ax, np.random.randn(10, 10), xticklabels=string.uppercase[:10], yticklabels=string.lowercase[-10:]
    )
コード例 #8
0
def test_pcolormesh_labels():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, np.random.randn(10, 10),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:])
コード例 #9
0
ファイル: pick_pts.py プロジェクト: mvenkat91/bigdata
def plot_days(days):
    nplots = len(days)
    fig, subplots = plt.subplots(nplots, figsize=(10, 50))
    for i, day in enumerate(days):
        subplot = subplots[i]
        plot_day(day, subplot)
    plt.tight_layout()
    plt.savefig('./plots/best.png')
コード例 #10
0
ファイル: test_hist.py プロジェクト: Lordie12/prettyplotlib
def test_scatter():
    # Set the random seed for consistency
    np.random.seed(12)

    fig, ax = plt.subplots(1)

    # Show some color range
    for i in range(2):
        x = np.random.randn(1000)
        ppl.hist(ax, x)
コード例 #11
0
def test_pcolormesh_positive_other_cmap():
    red_purple = brewer2mpl.get_map('RdPu', 'sequential', 8).mpl_colormap

    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, np.random.uniform(size=(10, 10)),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:],
                   cmap=red_purple)
コード例 #12
0
def test_legend():
    # Set the random seed for consistency
    np.random.seed(12)

    fig, ax = plt.subplots(1)

    # Show the whole color range
    for i in range(8):
        x = np.random.normal(loc=i, size=1000)
        y = np.random.normal(loc=i, size=1000)
        ppl.scatter(ax, x, y, label=str(i))
    ppl.legend(ax)
コード例 #13
0
ファイル: plot.py プロジェクト: gauden/hfadb
    def __init__(self, plot, langs=['en', 'ru']):
        self.plot = plot
        self.langs = langs
        self._set_defaults()

        self.figures = {}
        for lang in self.langs:
            self.plot.specs['facets'] = len(self.plot.specs['countries'])
            rows, cols = self._get_grid(self.plot.specs['facets'])
            self.plot.specs['cols'] = cols
            self.plot.specs['rows'] = rows
            figure, ax_array = plt.subplots(rows, cols)
            ax_array = self._hide_axes(ax_array, rows, cols)
            self.figures[lang] = (figure, ax_array)
コード例 #14
0
def test_plot():
    # Set the random seed for consistency
    np.random.seed(12)

    fig, ax = plt.subplots(1)

    # Show the whole color range
    for i in range(8):
        y = np.random.normal(size=1000).cumsum()
        x = np.arange(1000)

        # For now, you need to specify both x and y :(
        # Still figuring out how to specify just one
        ppl.plot(ax, x, y, label=str(i))
コード例 #15
0
    def draw_color_mesh(self):
        '''
        Draws a heatmap of pairs of heroes which co-occur
        in the winning and in the losing teams, useful to
        visualize the relationship between strong pairs of
        heroes which lead to victories vs. weak pairs of
        heroes which don't have much synergy
        '''
        red_yellow = brewer2mpl.get_map('YlGnBu', 'Sequential', 9).mpl_colormap

        fig, ax = plt.subplots(1, figsize=(13, 10))
        ax.set_xlim([0, self.c])
        ax.set_ylim([0, self.c])

        mesh = np.zeros((self.c, self.c), dtype=float)
        for i in range(0, self.c):
            for j in range(0, self.c):
                if i >= j:
                    # Same hero cannot be picked twice
                    continue

                if (i, j) in self.dwstat:
                    if self.ddstat[(i, j)] != 0:
                        k = round(
                            self.dwstat[(i, j)] /
                            float(self.ddstat[(i, j)] + self.dwstat[(i, j)]),
                            2)
                        mesh[i][j] = k
                        mesh[j][i] = k

        # *************************************************************** #
        # Code to calculate the max ratios in the heatmap
        # and obtain their hero indices too
        # Get the indices for the largest `num_largest` values.
        num_largest = 8
        indices = mesh.argpartition(mesh.size - num_largest,
                                    axis=None)[-num_largest:]
        x, y = np.unravel_index(indices, mesh.shape)
        print "full:"
        print "x =", x
        print "y =", y
        print "Largest values:", mesh[x, y]
        # print "Compare to:    ", np.sort(mesh, axis=None)[-num_largest:]
        # **************************************************************** #

        ppl.pcolormesh(fig, ax, mesh, cmap=red_yellow)
        fig.savefig('../Figures/HeatMap-heroPairs.png')
        plt.show()
        plt.clf()
コード例 #16
0
def test_pcolormesh_positive_other_cmap():
    red_purple = brewer2mpl.get_map("RdPu", "sequential", 8).mpl_colormap

    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(
        fig,
        ax,
        np.random.uniform(size=(10, 10)),
        xticklabels=string.uppercase[:10],
        yticklabels=string.lowercase[-10:],
        cmap=red_purple,
    )
コード例 #17
0
ファイル: hsp_viz.py プロジェクト: edraizen/hsp_tiler
def histogram(original, updated, bins=None, main="", save=None, log=False):
    """Plot a histogram of score improvements (updated-origianl)

    Input:
    original - list of original scores
    updated - list of updates scores in same order as original
    bins - number of bins to represent improvements
    """
    #Lengths of score lists must be identical, assume in same order
    assert len(original) == len(original)

    #Set up bins:
    if bins is not None and bins > 0:
        imoprovements = {(-1,-1):0}
        for i in xrange(0, len(original), bins):
            improvements[(0,i+bins)] = 0
    else:
        improvements = {(-1,-1):0, (-5,0):0, (0,1):0, (1,25):0, (25,50):0, (50,75):0, (75,100):0, (100,125):0, (125,150):0, (150,200):0, (200,300):0, (300,400):0, (500,10000):0} #defaultdict(int)
    
    #Calcualte improvements
    for o, u in izip(original, updated):
        if o>u: 
            improvements[(-1,-1)] += 1
            continue
        for lower, upper in improvements:
            if lower <= int(u-o) < upper:
                improvements[(lower,upper)] += 1
                break
    keys = sorted(improvements.keys(), key=lambda x:x[0])
    values = [improvements[r] for r in keys]

    fig, ax = plt.subplots()
    ax.set_title(main)
    ax.set_xlabel("Improvement (updated-original) bitscores")
    ax.set_ylabel("log(Frequency)")
    #ax.set_yscale('log')

    width = 1.0
    #ax.set_xticks(np.arange(len(improvements)))
    #ax.set_xticklabels([l for l, u in keys])
    bar(ax, np.arange(len(improvements)), values, log=log,
        annotate=True, grid='y', xticklabels=[l for l, u in keys])

    if save is None:
        plt.show()
    else:
        plt.savefig(save)
コード例 #18
0
def plot_prep_methods(df, prep, prepi, in_file):
    """Plot comparison between BAM preparation methods.
    """
    out_file = "%s-%s.png" % (os.path.splitext(in_file)[0], prep)
    cats = ["concordant", "discordant-missing-total",
            "discordant-extra-total", "discordant-shared-total"]
    cat_labels = {"concordant": "Concordant",
                  "discordant-missing-total": "Discordant (missing)",
                  "discordant-extra-total": "Discordant (extra)",
                  "discordant-shared-total": "Discordant (shared)"}
    vtype_labels = {"snp": "SNPs", "indel": "Indels"}
    prep_labels = {"gatk": "GATK best-practice BAM preparation (recalibration, realignment)",
                   "none": "Minimal BAM preparation (samtools de-duplication only)"}
    caller_labels = {"ensemble": "Ensemble", "freebayes": "FreeBayes",
                     "gatk": "GATK Unified\nGenotyper", "gatk-haplotype": "GATK Haplotype\nCaller"}
    vtypes = df["variant.type"].unique()
    fig, axs = plt.subplots(len(vtypes), len(cats))
    callers = sorted(df["caller"].unique())
    width = 0.8
    for i, vtype in enumerate(vtypes):
        for j, cat in enumerate(cats):
            ax = axs[i][j]
            if i == 0:
                ax.set_title(cat_labels[cat], size=14)
            ax.get_yaxis().set_ticks([])
            if j == 0:
                ax.set_ylabel(vtype_labels[vtype], size=14)
            vals, labels, maxval = _get_chart_info(df, vtype, cat, prep, callers)
            ppl.bar(ax, left=np.arange(len(callers)),
                    color=ppl.set2[prepi], width=width, height=vals)
            ax.set_ylim(0, maxval)
            if i == len(vtypes) - 1:
                ax.set_xticks(np.arange(len(callers)) + width / 2.0)
                ax.set_xticklabels([caller_labels[x] for x in callers], size=8, rotation=45)
            else:
                ax.get_xaxis().set_ticks([])
            _annotate(ax, labels, vals, np.arange(len(callers)), width)
    fig.text(.5, .95, prep_labels[prep], horizontalalignment='center', size=16)
    fig.subplots_adjust(left=0.05, right=0.95, top=0.87, bottom=0.15, wspace=0.1, hspace=0.1)
    #fig.tight_layout()
    fig.set_size_inches(10, 5)
    fig.savefig(out_file)
    return out_file
コード例 #19
0
    def hero_stats_bar(self, thresh):
        '''
        Creates a bar chart of the heroes with highest
        Wins / #Games played ratio
        '''
        # Create individual hero wins and losses
        self.hero_stats()

        fig, ax = plt.subplots(1, figsize=(9, 7))
        # Compute the ratio of #Wins to the #Games played by that hero
        # Most relevant statistic, better than W/L Ratio, better than
        # just wins, all of them can be statistically insignificant
        # in edge cases, but this can be the least of all
        val = [
            (k, self.wstat[k] / float(self.dstat[k] + self.wstat[k]))
            for k in self.wstat
            if self.wstat[k] / float(self.dstat[k] + self.wstat[k]) >= thresh
        ]
        plt.title('Hero ID vs. Win Ratio (Matches from 01/23 - 02/24)')
        plt.xlabel('Hero ID')
        plt.ylabel('Win Ratio')
        ax.set_xlim([0, len(val)])
        ann = [round(k[1], 2) for k in val]
        # Extract the xticklabels
        xtl = [k[0] for k in val]
        # Extract the individual values to be plotted
        val = [k[1] for k in val]
        ppl.bar(ax,
                np.arange(len(val)),
                val,
                annotate=ann,
                xticklabels=xtl,
                grid='y',
                color=ppl.colors.set2[2])
        fig.savefig('../Figures/HIDvs#Wins#Games.png')
        plt.show()
        plt.clf()
コード例 #20
0
## DO principales + vitalicios
## numero de socios por categoria
numero_socios = [str(len(principales) + len(vitalicios)),
                 str(250-len(principales)-len(vitalicios))]

print "Socios privilegiados con el voto " + str(len(principales) +
        len(vitalicios) + len(activos))

y = [princi_money + vitali_money, activo_money + otros_money]
annotate = [locale.format("%d", y[0], grouping=True) + " S/.",
            locale.format("%d", y[1], grouping=True) + " S/."]

width = 0.35
bar_color = ["r", "#66c2a5"]
plt.rc('font', **{'family': 'DejaVu Sans'})
fig, ax = plt.subplots(1, figsize=(8,6))
ind = np.arange(2)
xdata = ind + 0.05 + width
ax.bar(ind, y)
ax.set_xticks(ind + 0.4)
ax.set_xticklabels(["principales y vitalicios\n(" + numero_socios[0] + " socios)", 
                    "otros socios\n(" + numero_socios[1] + " socios)", 
                    ],
                    rotation="horizontal", multialignment="center")
ax.autoscale()
ax.set_title(u'Ganancias de socios principales y vitalicios\n comparados con el resto de socios',
        fontdict = {'fontsize':22}
        )

y_labels = ["0", "1,000,000", "2,000,000", "3,000,000", "4,000,000",
                "5,000,000", "6,000,000", "7,000,000", "8,000,000"]
コード例 #21
0
    out = np.zeros(n_datos)
    out[:tau] = lambda_1
    out[tau:] = lambda_2
    return out

observation = pm.Poisson("obs", lambda_, value=datos, observed=True)
model = pm.Model([observation, lambda_1, lambda_2, tau])
mcmc = pm.MCMC(model)
mcmc.sample(50000, 10000, 1)

lambda_1_samples = mcmc.trace('lambda_1')[:]
lambda_2_samples = mcmc.trace('lambda_2')[:]

tau_samples = mcmc.trace('tau')[:]

fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1)

plt.rc('font', **{'family': 'DejaVu Sans'})
plt.subplot(311)
plt.title(u'''Distribución posterior de las variables
            $\lambda_1,\;\lambda_2,\;tau$''')
plt.hist(lambda_1_samples, histtype="stepfilled", bins=30, alpha=0.85,
        normed=True)
plt.xlim([150000,250000])
plt.xlabel("valor de $\lambda_1$")


plt.subplot(312)
#ax.set_autoscaley_on(False)
plt.hist(lambda_2_samples, histtype="stepfilled", bins=30, alpha=0.85,
        normed=True)
コード例 #22
0
ファイル: top10.py プロジェクト: aniversarioperu/apdayc
            x.append(row[1])

counter = collections.Counter(x)
x = []
y = []
for i in sorted(counter, key=counter.get, reverse=True):
    if counter[i] != 1:
        x.append(i)
        y.append(counter[i])

for i in range(len(x)):
    print str(y[i]) + "," + str(x[i])


plt.rc('font', **{'family': 'DejaVu Sans'})
fig, ax = plt.subplots(1, figsize=(20,6))

width = 0.35
ind = np.arange(len(y))
xdata = ind + 0.05 + width
ax.bar(ind, y)
ax.set_xticks(ind + 0.5)
ax.set_xticklabels(x, rotation="vertical")
ax.autoscale()
ax.set_title(u'Ranking de canciones "Top 10"\n Radio Inspiración FM',
        fontdict = {'fontsize':24}
        )

plt.ylabel('Frecuencia en "Top 10"', fontdict={'fontsize':18})
plt.xlabel(u"Canción", fontdict={'fontsize':22})
コード例 #23
0
ファイル: bar_graphs.py プロジェクト: abner0908/plc
import prettyplotlib as ppl
import numpy as np
from prettyplotlib import plt

fig, ax = plt.subplots(1)

np.random.seed(14)

# 'y' for make a grid based on where the major ticks are on the y-axis
ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10)), grid='y')
# fig.savefig('bar_prettyplotlib_grid.png')
plt.show()
コード例 #24
0
ファイル: test_bar.py プロジェクト: akeshavan/prettyplotlib
def test_bar_annotate_user():
    fig, ax = plt.subplots(1)
    np.random.seed(14)
    ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10)),
            annotate=range(10,20))
コード例 #25
0
def graph(fname, analysis_fns = FN_TUPLES):   
    """
    Graphs mean and median of vector functions over a given starting
    percentage of relevant sentence ids.

    Arguments:
    fname -- the filename of the pickled output
    analysis_fns -- a list of (fn_name, fn) to run over the data
    """
    with open(fname) as f:
        results = pickle.load(f)
        test_set = results['test_set']
        vector_functions = results['vector_functions']
        step_percentage = results['step_percentage']
        results = results['results']  
        percents = sorted(results.keys())

        
        for fn_name, fn in analysis_fns:
            fig, ax = plt.subplots(1)
            ax.set_title(fn_name.capitalize())
            for vec_fn in vector_functions:
                xs = sorted(results.keys())
                x_axis = [x * 100 for x in xs]
                y_axis = [fn(results[percent][vec_fn]['recalls']) * 100 for percent in xs]
                ppl.plot(ax, x_axis, y_axis, label=vec_fn, linewidth=2, color=COLORS[vec_fn])

            ax.set_xticks([i * 100 for i in percents])
            ax.set_xlim([percents[0]*100, percents[-1]*100])

            ax.set_xlabel('Starting (%)')
            ax.set_ylabel('Recall (%)')
            if fn_name == 'std':
                ax.set_ylabel('Std')

            # shink current axis's height by 10% on the bottom for legend
            box = ax.get_position()
            ax.set_position([box.x0, box.y0 + box.height * 0.1,
                             box.width, box.height * 0.9])

            # put a legend below current axis
            ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1),
                      fancybox=True, shadow=True, ncol=5)

            fig.savefig('line_plot_{}_{}.png'.format(fn_name, test_set))

        fig, ax = plt.subplots(1)
        ax.set_title('Recalls')

        # jitter to see all series
        current = -(len(vector_functions) / 2)
        step = 1
        for vec_fn in vector_functions:
                # intermediate variables are for plebs
                x, y = zip(*[item for sublist in [[((percent*100)+current, val*100) for val in results[percent][vec_fn]['recalls']] for percent in percents] for item in sublist])
                current += step
                ppl.scatter(ax, x, y, label=vec_fn, facecolor=COLORS[vec_fn], alpha=0.3)

        # set x ticks and limit ranges
        ax.set_xticks([i * 100 for i in percents])
        ax.set_xlim([(percents[0] - step_percentage) * 100, (percents[-1] + step_percentage) * 100])
        ax.set_ylim([-5,100])

        ax.set_xlabel('Starting (%)')
        ax.set_ylabel('Recall (%)')

        # Shink current axis's height by 10% on the bottom
        box = ax.get_position()
        ax.set_position([box.x0, box.y0 + box.height * 0.1,
                         box.width, box.height * 0.9])

        # Put a legend below current axis
        ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1),
                  fancybox=True, shadow=True, ncol=5)

        fig.savefig('scatter_plot_{}.png'.format(test_set))
コード例 #26
0
ファイル: hsp_viz.py プロジェクト: edraizen/hsp_tiler
def scatter(original, updated, main="", save=None):
    """Plot a scatterplot of updated bitscores vs. original bitscores

    """ 
    #Remove hits with no improvement and calcate the number of hits with no
    #improvement(udated == original), positive imporvent (updated > original), 
    #and negative improvment (updated < original)
    print len(original)
    positiveImprovement = []
    negativeImprovement = []
    noImprovement = 0
    for o, u in izip(original, updated):
        if int(o) == int(u):
            noImprovement +=1
        elif u > o:
            positiveImprovement.append((o,u))
        elif u < o:
            negativeImprovement.append((o,u))
        else:
            noImprovement +=1

    if not positiveImprovement:
        positiveImprovement = [()]
    if not negativeImprovement:
        negativeImprovement = [()]

    print positiveImprovement
    print negativeImprovement
    print noImprovement

    #Set deimensions
    x, y = zip(*positiveImprovement+negativeImprovement)
    xMax = int(round(sorted(x)[-1]/500.0)*500.0)
    yMax = int(round(sorted(y)[-1]/500.0)*500.0)
    sep = 500
    xticks = range(0, xMax, sep)
    yticks = range(0,yMax,sep)
    color_cycle = brewer2mpl.get_map('Set2', 'qualitative', 8).mpl_colors

    fig, ax = plt.subplots()
    ax.set_title(main)
    ax.set_xlabel("Original Bitscores")
    ax.set_ylabel("Updated Bitscores")

    
    #Plot postive improvement (green, automatically by prettyplotlib)
    if positiveImprovement:
        ppl.scatter(ax, *zip(*positiveImprovement), 
                    label="Positive Improvement ({} seqs)".format(len(positiveImprovement)),
                    color=color_cycle[0])

    #Draw no improvement line
    ppl.plot(ax, (0,xMax), (0,xMax), color='k', linestyle='-', linewidth=2,
             label="No Improvement ({} seqs)".format(noImprovement))

    #Plot negative improvement (red, automatically by prettyplotlib)
    if negativeImprovement:
        ppl.scatter(ax, *zip(*negativeImprovement),
                    label="Negative Improvement ({} seqs)".format(len(negativeImprovement)),
                    color=color_cycle[1])

    #Draw labels
    ppl.legend(ax)

    #Set axis
    ax.set_ylim([0,yMax])
    ax.set_xlim([0,xMax])

    if save is None:
        plt.show()
    else:
        pp = PdfPages(save)
        pp.savefig(fig)
        pp.close()
コード例 #27
0
ファイル: cluster.py プロジェクト: stephentu/vldbtrends
def cluster_and_render(conf,
                       dbname,
                       algo_fn=kmeans_algo(8),
                       merge_fn=take_last_merge_strategy,
                       outname="./text.html"):

  db = sqlite3.connect(dbname)
  r = db.execute("select min(year), max(year) from counts")
  minyear, maxyear = r.fetchone()

  def vectors():
    r = db.execute("select word, year, c from counts order by word, year")
    vects = defaultdict(dict)
    for w,y,c in r:
      l = vects[w]
      l[y] = c

    ret = []
    words = []
    for w in vects:
      d = vects[w]
      counts = [d.get(y, 0) for y in xrange(minyear, maxyear+1)]
      ret.append(counts)
      words.append(w)
    return words, np.array(ret)

  words, counts = vectors()

  labels = merge_fn(algo_fn(counts))
  vects = smooth(counts)
  vects = np.array([[w] + list(v) for w, v in zip(words, vects)])
  for v in vects[:10]:
      print v

  #clusterer = KMeans(nclusters, n_init=30, init='k-means++')
  #data = vects[:,1:].astype(float)
  #data = np.array([l / max(l) for l in data ])
  #clusterer.fit(data) # words x year
  #labels = clusterer.labels_

  xs = np.array(range(minyear, maxyear+1))

  imgs = []
  content = []

  def add_content(subcluster, content, suffix):
      fig, ax = plt.subplots(1, figsize=(6.5,2.5))
      for childax in ax.get_children():
        if isinstance(childax, mpl.spines.Spine):
          childax.set_color('#aaaaaa')
      for i in ax.get_xticklabels():
        i.set_color('#aaaaaa')
      for i in ax.get_yticklabels():
        i.set_color('#aaaaaa')

      subcluster = sorted(subcluster, key=lambda t: max(t[1:].astype(float)), reverse=True)[:10]
      subcluster = np.array(subcluster)
      words = subcluster[:,0]
      ys = subcluster[:,1:].astype(float)
      mean = [np.mean(ys[:,i]) for i in xrange(ys.shape[1])]
      ys = ys.transpose()
      ax.set_ylim(top=max(10, max(map(max, ys))))

      ppl.plot(ax, xs, ys, alpha=0.3, color="#7777ee")
      ppl.plot(ax, xs, mean, alpha=1, color="black")
      fname = './plots/%s_%s.png' % (conf, suffix)
      fig.savefig(fname, format='png')

      maxes = map(max, ys)
      idx = maxes.index(max(maxes))
      content.append(('', words, fname, idx))



  for label in set(labels):
    fig, ax = plt.subplots(1, figsize=(13, 5))

    idxs = labels == label
    cluster = vects[idxs]
    cluster = sorted(cluster, key=lambda t: max(t[1:].astype(float)), reverse=True)
    cluster = filter(lambda l: sum(map(float, l[1:])) > 4, cluster)
    if len(cluster) < 10: continue
    cluster = np.array(cluster)
    words = cluster[:,0]
    words = list(words)

    #if 'crowd' in words:
    #  data = cluster[:,1:].astype(float)
    #  data = np.array([l / max(l) for l in data])
    #  clusterer = KMeans(2)
    #  clusterer.fit(data)
    #  for newlabel in set(clusterer.labels_):
    #    idxs = clusterer.labels_ == newlabel
    #    subcluster = cluster[idxs]
    #    add_content(subcluster, content, "%s-%s" % (label, newlabel))
    #  continue

    cluster = cluster[:10]
    add_content(cluster, content, label)

  content.sort(key=lambda c: c[-1])

  from jinja2 import Template
  template = Template(file('./clustertemplate.html').read())


  with file(outname, 'w') as f:
    f.write( template.render(content=content))
コード例 #28
0
def main():
    description = """Simple bar plot of table. Input is a table from a file or
    standard input."""

    parser = argparse.ArgumentParser(
        description=description,
        formatter_class=RawTextHelpFormatter
    )
    parser.add_argument(
        '-f',
        '--filename',
        action='store',
        metavar='table.csv',
        help='''A table of the format:
                x_title,  y_title,  Main_title
                x_label1, value1
                x_label2, value2''',
        required=False,
        dest='filename',
    )

    args = parser.parse_args()

    if args.filename:
        filename = args.filename.strip()
    else:
        parser.print_help()
        sys.exit(1)

    y = []
    x = []
    for line in open(filename, "r").readlines():
        line = line.strip()

        res = re.search("[0-9]+", line)
        if not res:
            line = line.split(",")
            x_lab = line[0]
            y_lab = line[1]
            main = line[2]
        else:
            line = line.split(",")
            if len(line) < 2:
                y.append(float(line[0]))
            else:
                x.append(line[0])
                y.append(float(line[1]))
            print(line)

    if len(x) < 1:
        x = range(1, len(y) + 1)

    plt.rc('font', **{'family': 'DejaVu Sans'})
    fig, ax = plt.subplots(1, figsize=(8, 6))

    width = 0.2
    ind = np.arange(len(y))
    xdata = ind + 0.05 + width
    ax.bar(ind, y)
    ax.set_xticks(ind + 0.5)
    ax.set_xticklabels(x)
    ax.autoscale()
    ax.set_title(
        main,
        fontdict={'fontsize': 20},
    )

    plt.ylabel(y_lab, fontdict={'fontsize': 15})
    plt.xlabel(x_lab, fontdict={'fontsize': 15})
    plt.tick_params(axis="y", which="major", labelsize=10)
    plt.tick_params(axis="x", which="major", labelsize=10)

    ppl.bar(ax, np.arange(len(y)), y, grid="y")

    plt.tight_layout()
    print("The plot has been saved as ``out.png``")
    fig.savefig("out.png")
コード例 #29
0
def test_bar_xticklabels():
    fig, ax = plt.subplots(1)
    np.random.seed(14)
    n = 10
    ppl.bar(ax, np.arange(n), np.abs(np.random.randn(n)),
            xticklabels=string.uppercase[:n])
コード例 #30
0
                for x in range(count):
                    data[locat].append(value)

print("data")
for i in data:
    print(i[:10])
print("data")

#np.random.seed(10)

#data = np.random.randn(8, 4)

u_labels = ['1e-7 mid','1e-7 end','1e-6 mid','1e-6 end','1e-5 mid','1e-5 end','1e-4 mid','1e-4 end','0.001 mid','0.001 end','0.005 mid','0.005 end','0.01 mid','0.01 end',\
        '0.05 mid', '0.05 end','0.1 mid','0.1 end']

fig, ax = plt.subplots()

ax.set_xticklabels(u_labels)
ax.set_xticks(u_labels)
ax.set_xlabel('Initial Mutation Rates', fontsize=9)
ax.set_ylabel('End Proliferation Rates', fontsize=9)
i = 0
print(ax.get_xticklabels())
ppl.boxplot(ax, data)  #,xticklabels=u_labels)
plt.title("Distribution of End Proliferation Rates by Initial Mutation Rate",
          fontsize=9)
fig.savefig(opt.output + '_boxplot.png')
print(opt.output + "DONE")
#ppl.hist(ax,data)
#fig.savefig('histogram_prettyplotlib_default.png')
コード例 #31
0
    out[:tau] = lambda_1
    out[tau:] = lambda_2
    return out


observation = pm.Poisson("obs", lambda_, value=datos, observed=True)
model = pm.Model([observation, lambda_1, lambda_2, tau])
mcmc = pm.MCMC(model)
mcmc.sample(50000, 10000, 1)

lambda_1_samples = mcmc.trace('lambda_1')[:]
lambda_2_samples = mcmc.trace('lambda_2')[:]

tau_samples = mcmc.trace('tau')[:]

fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1)

plt.rc('font', **{'family': 'DejaVu Sans'})
plt.subplot(311)
plt.title(u'''Distribución posterior de las variables
            $\lambda_1,\;\lambda_2,\;tau$''')
plt.hist(lambda_1_samples,
         histtype="stepfilled",
         bins=30,
         alpha=0.85,
         normed=True)
plt.xlim([150000, 250000])
plt.xlabel("valor de $\lambda_1$")

plt.subplot(312)
#ax.set_autoscaley_on(False)
コード例 #32
0
ファイル: test_bar.py プロジェクト: akeshavan/prettyplotlib
def test_bar_grid():
    fig, ax = plt.subplots(1)
    np.random.seed(14)
    ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10)), grid='y')
コード例 #33
0
        author = author[0].capitalize() + " " + author[1].capitalize()

        if author in apdayc:
            bar_color.append("r")
        else:
            bar_color.append("#66c2a5")

        money = i[1].split(" ")
        total_money = money[len(money)-1]
        x.append(author)
        y.append(total_money)

y = map(float, y)

plt.rc('font', **{'family': 'DejaVu Sans'})
fig, ax = plt.subplots(1, figsize=(40,6))

width = 0.35
ind = np.arange(len(y))
xdata = ind + 0.05 + width
ax.bar(ind, y)
ax.set_xticks(ind + 0.5)
ax.set_xticklabels(x, rotation="vertical")
ax.autoscale()
ax.set_title(u'Los Asociados de APDAYC que cobraron más dinero en el 2012\nen color rojo figuran los miembros del Consejo Directivo',
        fontdict = {'fontsize':24}
        )

y_labels = ["0", "200,000", "400,000", "600,000", "800,000", "1,000,000"]
ax.set_yticklabels(y_labels)
コード例 #34
0
ファイル: test_bar.py プロジェクト: akeshavan/prettyplotlib
def test_bar_xticklabels():
    fig, ax = plt.subplots(1)
    np.random.seed(14)
    n = 10
    ppl.bar(ax, np.arange(n), np.abs(np.random.randn(n)),
            xticklabels=UPPERCASE_CHARS[:n])
コード例 #35
0
def test_pcolormesh():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, np.random.randn(10, 10))