Exemplo n.º 1
0
 def createBokehChart(self):
     plotwidth = int(self.getPreferredOutputWidth() / 2)
     plotheight = int(self.getPreferredOutputHeight() * 0.75)
     defaultbin = math.sqrt(len(self.getWorkingPandasDataFrame().index))
     binsize = int(self.options.get('binsize', defaultbin))
     valueFields = self.getValueFields()
     histograms = []
     if len(valueFields) != 1:
         for i, valueField in enumerate(valueFields):
             color = self.options.get("color")
             if color is None:
                 color = Colors.hexRGB(1. * i / 2)
             histograms.append(
                 Histogram(self.getWorkingPandasDataFrame(),
                           values=valueField,
                           plot_width=plotwidth,
                           plot_height=plotheight,
                           bins=binsize,
                           color=color,
                           xgrid=True,
                           ygrid=True,
                           ylabel='Frequency'))
         return histograms
     else:
         return Histogram(self.getWorkingPandasDataFrame(),
                          values=self.getValueFields()[0],
                          bins=binsize,
                          color=self.options.get("color"),
                          xgrid=True,
                          ygrid=True,
                          ylabel='Frequency')
Exemplo n.º 2
0
    def createBokehChart(self):
        plotwidth = int(self.getPreferredOutputWidth() / 2)
        plotheight = int(self.getPreferredOutputHeight() * 0.75)
        binsize = int(self.options.get('binsize', 10))
        valueFields = self.getValueFields()
        histograms = []
        if len(valueFields) != 1:
            for i in valueFields:
                histograms.append(
                    Histogram(self.getWorkingPandasDataFrame(),
                              values=i,
                              plot_width=plotwidth,
                              plot_height=plotheight,
                              bins=binsize,
                              color=self.options.get("color"),
                              xgrid=True,
                              ygrid=True))

            return histograms
        else:
            return Histogram(self.getWorkingPandasDataFrame(),
                             values=self.getValueFields()[0],
                             bins=binsize,
                             color=self.options.get("color"),
                             xgrid=True,
                             ygrid=True)
Exemplo n.º 3
0
def plot_histogram(same, diff):
    df = {"PAINS vs. PAINS": same, "PAINS vs. ChEMBL": diff}
    output_file("histogram_pains_self_diff.html")
    hist = Histogram(df, bins=20, density=True, legend=True)
    hist.x_range = Range1d(0, 1)
    #hist.legend.orientation = "top_right"
    show(hist)
Exemplo n.º 4
0
    def exibir(self):
        for i in self.dados.keys():
            if len(self.dados[i]) > 0: continue
            else: return
        defaults.width, defaults.height = 400, 300
        # prepare some data
        # input options
        hist_pontuacao = Histogram(self.dados["pontos"],
                                   title="Grades por pontuação",
                                   xlabel="Pontuação",
                                   ylabel="Número de grades",
                                   responsive=True,
                                   bins=30)

        hist_tamanho = Histogram(self.dados["tamanhos"],
                                 title="Grades por quantidade de disciplinas",
                                 xlabel="Número de disciplinas",
                                 ylabel="Número de grades",
                                 responsive=True,
                                 bins=8)

        hist_pop = Histogram(self.dados["popularidade"],
                             title="Ocorrências da disciplina x",
                             xlabel="Disciplina",
                             ylabel="Ocorrências nas grades",
                             responsive=True,
                             bins=46)

        output_file("html/histograms.html")

        show(hplot(hist_pontuacao, hist_tamanho, hist_pop))
Exemplo n.º 5
0
def plot_actions_players_min(actions: dict, output_file_url: str) -> None:
    """
    Plots all actions in a line diagrams and outputs them to an html file.
    :param actions: a list of all actions and their timestamp.
    :param output_file_url: string containing the directory and filename
    :return: None
    """
    # output to static HTML file
    output_file(output_file_url)
    tabs = []
    for action in actions:
        # create a new plot with a title and axis labels
        p = Histogram(actions[action],
                      title=action,
                      bins=[0, 15, 30, 45, 60, 75, 90, 105])
        p.xaxis.axis_label = 'Tijd (min.)'
        p.yaxis.axis_label = 'Frequentie'
        p.x_range = Range1d(0, 105)

        # create a tab
        tab = Panel(child=p, title=action)
        # add to existing tabs
        tabs.append(tab)

    tabs = Tabs(tabs=tabs)

    # show the results
    show(tabs)
Exemplo n.º 6
0
def plot_times(dataframe):
    dataframe = dataframe.fillna(-1)
    p = Histogram(dataframe,'total time',bins=24, color = 'green',
        title="Processing Times",height=500,width=1000)
    text = """Mean: {mean}
            Min: {min}
            Max: {max}""".format(mean=round(dataframe[dataframe.status==0]['total time'].mean(skipna=True),3),min = dataframe[dataframe.status==0]['total time'].min(),max=dataframe[dataframe.status==0]['total time'].max())
    mytext = glyphs.Text(x=p.x_range.end-(p.x_range.end/3), y=p.y_range.end - (p.y_range.end/3),text=[text],text_font_size='10pt')
    p.add_glyph(mytext)
    return p
Exemplo n.º 7
0
    def histogram(self,
                  dataframe,
                  bins=None,
                  width=None,
                  height=None,
                  palette=None,
                  title='Histogram',
                  values=None,
                  groups=None,
                  legend=True):
        palette = self.__default_options__.get(
            'palette', None) if palette is None else palette
        width = self.__default_options__.get('width',
                                             None) if width is None else width

        if values:
            unique_values = dataframe[groups].unique()
            palette = self._palette(palette, len(unique_values))
        else:
            palette = None

        width, height = self._width_height(width, height)

        histogram = Histogram(dataframe,
                              values=values,
                              color=groups,
                              bins=bins,
                              legend=True,
                              width=width,
                              height=height,
                              palette=palette,
                              title=title)

        return histogram
Exemplo n.º 8
0
def Histograms():
    plot = Histogram(df,
                     values=value,
                     color=value,
                     title=title,
                     legend='top_right')
    #    script, div = components(plot)
    return plot
Exemplo n.º 9
0
    def showBacktestingResult(self):
        """显示回测结果"""
        d = self.calculateBacktestingResult()

        # 输出
        self.output('-' * 30)
        self.output('First Trade:\t%s' % d['timeList'][0])
        self.output('Last Trade:\t%s' % d['timeList'][-1])

        self.output('Total Trades:\t%s' % formatNumber(d['totalResult']))
        self.output('Total Return:\t%s' % formatNumber(d['capital']))
        self.output('Maximum Drawdown: \t%s' %
                    formatNumber(min(d['drawdownList'])))

        self.output('Ave Trade:\t%s' %
                    formatNumber(d['capital'] / d['totalResult']))
        self.output('Ave Slippage:\t%s' %
                    formatNumber(d['totalSlippage'] / d['totalResult']))
        self.output('Ave Commission:\t%s' %
                    formatNumber(d['totalCommission'] / d['totalResult']))

        self.output('Win Ratio\t\t%s%%' % formatNumber(d['winningRate']))
        self.output('Ave Win\t%s' % formatNumber(d['averageWinning']))
        self.output('Ave Loss\t%s' % formatNumber(d['averageLosing']))
        self.output('Profit Factor:\t%s' % formatNumber(d['profitLossRatio']))

        # Use Bokeh to plot
        from bokeh.charts import Area, Line, Histogram
        from bokeh.layouts import column
        from bokeh.io import show

        plotdata = {
            "TradeN": range(len(d['capitalList'])),
            "Equity Curve": d['capitalList'],
            "Maximum Drawdown": d['drawdownList'],
            "Profit/Loss": d['pnlList']
        }

        f1 = Line(plotdata,
                  x="TradeN",
                  y="Equity Curve",
                  color="blue",
                  width=1000,
                  height=300)
        f2 = Area(plotdata,
                  x="TradeN",
                  y="Maximum Drawdown",
                  color="tomato",
                  width=1000,
                  height=300)
        f3 = Histogram(plotdata,
                       values="Profit/Loss",
                       bins=30,
                       color="green",
                       width=1000,
                       height=300)

        show(column(f1, f2, f3))
Exemplo n.º 10
0
def nbd():
    #pull 'nbd' from input field and store it:
    nbd = request.args.get('nbd')
    room_type = "Private room"


    #nbd = "East Village"

    train = pd.read_sql_query("""
                           SELECT * FROM listings_price
                           WHERE neighbourhood_cleansed = %(nbd)s
                           AND room_type = %(room_type)s;
                           """,
                           con, index_col = "id",
                           params = {"nbd":nbd, "room_type":room_type})


    #train

    train["ratio"] = (train["preds"] - train["price"])/train["price"]




    #keep train for the histogram
    sm_train = train[train["ratio"] > 0][train["ratio"] < 1.2]
    sm_train = sm_train.sort_values("diff", ascending = False)


    sm_train["diff"]
    births = []


    #showing some tables:
    for i in range(0,25):
       births.append(dict(price=int(sm_train.iloc[i]['price']),
                          city=sm_train.iloc[i]['name'],
                          id = sm_train.index[i],
                          room_type=int(sm_train.iloc[i]['preds']),
                          url=sm_train.iloc[i]['listing_url']))
       the_result = ''


    #births
    plot = Histogram(train["price"], bins = 20, plot_width=500, plot_height=300)
    script, div = components(plot)
    title = "Distribution of daily prices in {0}".format(nbd)

    median = train["price"].median()
    percentile_05 = np.round(train["price"].quantile(0.05), 1)
    percentile_95 = np.round(train["price"].quantile(0.95), 1)

    more_info = "The median price per day is ${0}. 95% of the listings are in \
                 between ${1} and ${2}".format(median, percentile_05, percentile_95)

    return render_template('nbd.html', births = births, the_result = the_result, nbd = nbd,
                           script = script, div = div, title = title, more_info = more_info)
Exemplo n.º 11
0
def create_figure(current_feature_name, bins):
	p = Histogram(iris_df, current_feature_name, title=current_feature_name, color='Species', 
	 	bins=bins, legend='top_right', width=600, height=400)

	# Set the x axis label
	p.xaxis.axis_label = current_feature_name

	# Set the y axis label
	p.yaxis.axis_label = 'Count'
	return p
Exemplo n.º 12
0
def create_histogram2(data):
    TOOLS = [HoverTool(tooltips=[('Age:', '$x{int}'), ('total', '@y')])]
    plot = Histogram(data,
                     title='Age:',
                     legend='bottom_right',
                     ylabel="Number of Tournaments",
                     tools=TOOLS,
                     plot_width=400,
                     plot_height=400)
    return plot
Exemplo n.º 13
0
def histograms(Y, bins=50, title='', xlabel='', height=3):
    df = {xlabel: Y}
    df = pd.DataFrame(df)
    plot = Histogram(df,
                     xlabel,
                     legend=None,
                     bins=bins,
                     title=title,
                     plot_height=int(height * ht),
                     sizing_mode='scale_width')
    return plot
Exemplo n.º 14
0
def showHistogram(times):
    mydict = {'Time (s)': totalboot(times)}

    hist = Histogram(pd.DataFrame(mydict),
                     values="Time (s)",
                     title="Total Boot Time (s)",
                     legend="top_right",
                     background_fill_alpha=0.6,
                     bar_width=1)

    show(hist)
Exemplo n.º 15
0
def plot_distance_distrib(G):
    """
    Plots the distribution of distances from the Graph
    """
    W = list([G[x][y]['weight'] for (x, y) in G.edges()])
    h = Histogram(W,
                  title="Weight (proximity) distribution",
                  xlabel='weights',
                  ylabel="Counts(weights)",
                  bins=50)
    return h
Exemplo n.º 16
0
def test_responsive_chart_starts_at_correct_size(output_file_url, selenium):
    hist = Histogram(df['mpg'], title="MPG Distribution", responsive=True)
    save(hist)

    selenium.set_window_size(width=1000, height=600)
    selenium.get(output_file_url)

    canvas = selenium.find_element_by_tag_name('canvas')
    wait_for_canvas_resize(canvas, selenium)

    # Canvas width should be just under 1000
    assert canvas.size['width'] > 900
    assert canvas.size['width'] < 1000
Exemplo n.º 17
0
def generate_histogram(table_data, form_data):
    """Generate histogram."""
    if form_data['color'] == '':
        color = 'blue'
    else:
        color = form_data['color']
    plot = Histogram(table_data,
                     values=form_data['column'],
                     color=color,
                     tools='pan,wheel_zoom,box_zoom,reset,resize,hover,save')
    plot.title.text_font_style = "bold"
    output_file("output.html")
    save(plot)
    return build_html()
Exemplo n.º 18
0
    def get(self, request):
        nyse = Listing.objects.filter(exchange='2').count()
        nasdaq = Listing.objects.filter(exchange='3').count()
        amex = Listing.objects.filter(exchange='1').count()
        asx = Listing.objects.filter(exchange='4').count()


        exchanges = ["NYSE", "NASDAQ", "AMEX", "ASX"]
        values = [nyse, nasdaq, amex, asx  ]

        # Bar Chart
        plot = figure(plot_width=400,
                      plot_height=400,
                      x_range=exchanges,
                      title="Number of Listings")
        plot.vbar(x=exchanges,
                  width=0.5,
                  bottom=0,
                  top=values,
                  color="navy")

        script, div = components(plot)

        #average_board_size = BoardMember.objects.values_list('id', flat=True)
        #average_board_size = BoardMember.objects.all().values('id').query
        #average_board_size = list(BoardMember.objects.values_list('id', flat=True))

        board_sizes = list(BoardMember.objects.all().values('company').annotate(Count('director')).values_list('director__count', flat=True))
        board_statistics = BoardStatistics(board_sizes)

        director_ages = list(filter(None, Director.objects.all().values_list('age', flat=True)))
        director_statistics = BoardStatistics(director_ages)

        plot = Histogram(board_sizes)

        histogram_script, histogram_div = components(plot)

        return render(request, self.template_name, {
            'bokeh_script': script,
            'bokeh_div': div,
            'bokeh_histogram_div': histogram_div,
            'bokeh_histogram_script': histogram_script,
            'total_companies': Company.objects.count(),
            'total_directors': Director.objects.count(),
            'last_update': str(Version.last_update),
            'total_listings': Listing.objects.count(),
            'board_statistics': board_statistics,
            'director_statistics': director_statistics
        })
Exemplo n.º 19
0
def test_responsive_chart_starts_at_correct_size(output_file_url, selenium):
    hist = Histogram(df['mpg'], title="MPG Distribution", responsive=True)
    save(hist)

    selenium.set_window_size(width=1000, height=600)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    canvas = selenium.find_element_by_tag_name('canvas')
    wait_for_canvas_resize(canvas, selenium)

    # Canvas width should be just under 1000 * 0.9
    # (default file_html has a body width of 90%)
    assert canvas.size['width'] > 850
    assert canvas.size['width'] < 900
Exemplo n.º 20
0
def simplePlotter(room, datetime, chartpick):

    df_day_counts = pd.read_sql_query(
        day_count_query.format(date=datetime, room=room), connectDB())

    # df_day_survey_counts = pd.read_sql_query(day_count_and_survey_query.format(date=datetime, room=room),
    #                                     connectDB())

    if chartpick == 'Histogram':
        plot = Histogram(df_day_counts['count'], title="Counts", bins=10)
    if chartpick == 'Bar':
        plot = Bar(df_day_counts['count'], title="Counts")

    all_plots = gridplot([[plot]])

    return all_plots
Exemplo n.º 21
0
def ticker(ticker):
    # build line
    line = Line(betalyzer.df_betas[ticker], plot_width=1000, plot_height=400)
    bokeh_script, bokeh_div = components(line)

    # build scatter
    scatter = Scatter(betalyzer.df_changes.head(betalyzer.window),
                      x=betalyzer.market,
                      y=ticker,
                      plot_width=550,
                      plot_height=400)
    scatter_script, scatter_div = components(scatter)

    # build histogram
    df_hist = betalyzer.df_changes[[ticker,
                                    'SPY']].head(500).unstack().reset_index()
    df_hist.rename(columns={'level_0': 'ticker', 0: 'change'}, inplace=True)
    hist = Histogram(df_hist,
                     values='change',
                     color='ticker',
                     bins=20,
                     legend='top_right',
                     plot_width=550,
                     plot_height=400)
    hist_script, hist_div = components(hist)

    return render_template(
        'ticker.html',
        ticker=ticker,
        bokeh_script=bokeh_script,
        bokeh_div=bokeh_div,
        scatter_script=scatter_script,
        scatter_div=scatter_div,
        hist_script=hist_script,
        hist_div=hist_div,
        window=betalyzer.window,
        dt_ticker=betalyzer.df_tickers.loc[ticker].to_dict())
Exemplo n.º 22
0
import numpy as np
import pandas as pd

from bokeh.charts import Histogram, show, output_file

# build some distributions and load them into a dict
mu, sigma = 0, 0.5
normal = np.random.normal(mu, sigma, 1000)
lognormal = np.random.lognormal(mu, sigma, 1000)
distributions = OrderedDict(normal=normal, lognormal=lognormal)

# create a pandas data frame from the dict
df = pd.DataFrame(distributions)
distributions = df.to_dict()

for k, v in distributions.items():
    distributions[k] = v.values()

# any of the following commented are valid Histogram inputs
#df = list(distributions.values())
#df = tuple(distributions.values())
#df = tuple([tuple(x) for x in distributions.values()])
#df = np.array(list(distributions.values()))
#df = list(distributions.values())[0]

output_file("histograms.html")

hist = Histogram(df, bins=50, legend=True)

show(hist)
#%matplotlib inline
#pylab.rcParams['figure.figsize'] = (10, 6)
def convert_int(dataframe, colname):
    dataframe[colname] = pd.to_numeric(dataframe[colname], errors='coerce')


limit_rows = 1000000
df = pd.read_csv("C:/Users/vasir/Desktop/ADM/train_ver2.CSV", nrows=limit_rows)

convert_int(df, 'age')
print df['age'].dtype
df['age'] = df['age'].fillna(-1)
cols = ['age']
df[cols] = df[cols].applymap(np.int64)
df_frac = df.sample(frac=0.01)
p_age = Histogram(df_frac, values='age', title="Age Distribution")
#show(p_age)

dffrac1 = df_frac.dropna(subset=['sexo'], how='any')
dffrac1.head()
#dffrac1['sexo']=dffrac1['sexo'].astype('category')
p = Bar(dffrac1, 'sexo', title="Sex")
#show(p)

dffrac2 = df_frac.dropna(subset=['renta'], how='any')
bar_renta = Bar(dffrac2,
                values='renta',
                label='nomprov',
                agg='mean',
                title="City Vs Renta",
                legend=False,
Exemplo n.º 24
0
from bokeh.charts import Histogram, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Histogram(df, values='hp', color='navy', title="HP Distribution")

output_file("histogram_color.html")

show(p)
get_ipython().system(
    u'curl --upload-file restaraunts.html https://transfer.sh/restaruants.html'
)

# In[93]:

from bokeh.io import output_notebook
output_notebook()

# In[94]:

from bokeh.charts import Histogram, output_file, show

# In[96]:

p1 = Histogram(samp["SCORE"])
show(p1)

# In[103]:

p2 = Histogram(mRests,
               'SCORE',
               color='GRADE',
               title="Score Grouped by Grade",
               bins=15,
               legend='top_left')

show(p2)

# In[99]:
def plot_prediction_histogram(images_path,
                              model_path,
                              weights_path,
                              img_shape,
                              required_class,
                              class_name_dict={},
                              batch_size=16,
                              preprocessing_function=None,
                              plotting_module="matplotlib"):
    """ Function to plot the histogram of predicted probabilities of a given class

    images_path --str: full path to the parent directory containing sub-directory(classes) of images
    model_path --str: full path to a keras model (.json file) (No default)
    weights_path --str: full path to the weights file (.hdf5 file) (No default)
    img_shape --tuple: image shape to input to the model (eg : (224,224,3)) (No default)
    required_class --str: The name of the required class on which to generate ROC (example "dog")
    class_name_dict --dict: Dictionary mapping of classes (default {})
    batch_size --int: The batch_size to use for prediction (Default 16)
    preprocessing_function --function: The preprocessing function to use before prediction (Default None)
    plotting_module --str: The plotting module to use. Either of 'matplotlib' or 'bokeh' (Default matplotlib)

    Output:
    Plots the histogram of the predicted probabilites of the required class

    """
    if len(class_name_dict) == 0:
        raise ValueError("Provide the class_name_dict")

    # loading model and weights
    json_file = open(model_path, 'r')
    loaded_model_json = json_file.read()
    json_file.close()
    loaded_model = model_from_json(loaded_model_json)
    # load weights
    loaded_model.load_weights(weights_path)
    print('loaded model from disk')
    # generator for data
    test_datagen = ImageDataGenerator(
        preprocessing_function=preprocessing_function)
    test_generator = test_datagen.flow_from_directory(
        images_path,
        target_size=(img_shape[0], img_shape[1]),
        class_mode='categorical',
        batch_size=batch_size,
        shuffle=False,  # to get ordered result
    )
    # this is an important step else there is a difference in result between predict and predict_generator
    test_generator.reset()  # reset to start with sample 0
    nb_samples = test_generator.samples
    class_name_dict = test_generator.class_indices  # eg {'dog': 0, 'cat': 1}
    # predict
    predictions = loaded_model.predict_generator(test_generator,
                                                 steps=nb_samples //
                                                 batch_size,
                                                 max_queue_size=10,
                                                 workers=1,
                                                 use_multiprocessing=False,
                                                 verbose=1)
    class_idx = class_name_dict[required_class]
    hist_data = predictions[:, class_idx]

    if plotting_module == "matplotlib":
        plt.hist(hist_data, bins=10)
        plt.xlim(0, 1)
        plt.title('Histogram of predicted probabilities')
        plt.xlabel('Predicted probability of {}'.format(required_class))
        plt.ylabel('Frequency')

    elif plotting_module == "bokeh":
        df = pd.DataFrame(
            {"Predicted probability of {}".format(required_class): hist_data})
        from bokeh.io import output_notebook
        import warnings
        warnings.filterwarnings('ignore')
        from bokeh.charts import Histogram, show
        output_notebook()
        p = Histogram(df,
                      "Predicted probability of {}".format(required_class),
                      title="Histogram of predicted probabilities")
        show(p)

    else:
        raise ValueError("Only bokeh and matplotlib are supported")
Exemplo n.º 27
0
import numpy as np

# we build some distributions and load them into a dict
mu, sigma = 0, 0.5
normal = np.random.normal(mu, sigma, 1000)
lognormal = np.random.lognormal(mu, sigma, 1000)
distributions = dict(normal=normal, lognormal=lognormal)

# then we create a pandas df from the dict
import pandas as pd
df = pd.DataFrame(distributions)

# and finally we drop the df into out Histogram chart
from bokeh.charts import Histogram
hist = Histogram(df, bins=50, filename="histograms.html")
hist.title("Histograms").ylabel("frequency").legend(True).width(400).height(350).show()
Exemplo n.º 28
0
def histogram(histDF, values, **kwargs):
    from bokeh.charts import Histogram
    return Histogram(histDF[values], **kwargs)
Exemplo n.º 29
0
def compute_plot_all_Deff(tmin, tmax, particle_chemistry):
    """
    Calculates and plots all Deffs in the timepoint range.

    This function trims the cleaned MSD pandas dataframe to the user-
    selected timepoint range, calculates a Deff from the mean MSD for
    each timepoint within the range and for each particle chemistry,
    plots a line graph of all Deffs across the timepoint range, and
    gives geometric mean Deff values for each chemistry for the time
    range specified.
    Note: tmin must be less than tmax to get a timepoint range.  If,
    however, the user requires a Deff calculated from a single
    timepoint, he or she can input an equal tmin and tmax, and the
    function will consider only the single closest timepoint (on the
    later side) to the input.

    Inputs:
    tmin: a float representing the minimum timepoint the user wishes to
    consider in the Deff calculation
    tmax: a float representing the maximum timepoint the user wishes to
    consider in the Deff calculation (make this the same as tmin if a
    single-timepoint Deff is desired)
    particle_chemistry: a string matching the column title of the
    particle chemistry which is to be emphasized: the Deffs of this
    chemistry will be plotted on the histogram, bolded/dashed on the
    line plot, and printed in the form of a geometric mean.

    Outputs:
    A bokeh histogram of Deffs for the inputted chemistry, on the same
    figure as the below line plot (this figure defaults to fit nicely
    in a 1280x800 screen, but plots can be resized as needed)
    A bokeh line plot of Deffs for all particle chemistries across the
    timepoint range, with emphasized chemistry bolded/dashed
    Deff of inputted chemistry: a geometric mean of the Deffs between
    tmin and tmax for the inputted chemistry, printed in the form of
    a string within an explanatory sentence
    avg_Deffs: a fresh pandas dataframe indexed with the columns
    (particle chemistries) of the MSD dataframe, containing single
    geometric mean Deff values for each particle chemistry
    """
    # Verify time range validity
    if tmin < 0 or tmax > round(max(msd.index)):
        return "Error: input time range between 0 and your data's tmax"
    else:
        if tmin == 0:
            print 'Divide by 0 error: tmin=0 changed to tmin=0.01'
            tmin = 0.01
        # Trim out-of-time-range rows
        temp1_msd = msd[msd.index >= tmin]
        # Trim to a length of 1 if user desires single-timepoint Deff
        if tmin == tmax:
            temp2_msd = temp1_msd.head(1)
        else:
            temp2_msd = temp1_msd[temp1_msd.index <= tmax]
            # Calculate Deffs for only the timepoints needed and add as
            # a new column to a new dataframe
            index = temp2_msd.index
            Deffs = pd.DataFrame(index=index, columns=columns2)
            avg_Deffs = pd.DataFrame(index=columns2)
            avg_Deffs_temp = []
            h = Histogram([1], bins=50, width=300, height=250)
            # maxes will eventually be used for sizing the histogram
            maxes = []
            # Lay the foundation for the bokeh figure
            output_file('Deffs_hist_and_line_plot.html')
            p = figure(
                tools='resize,pan,box_zoom,wheel_zoom,reset,save', width=950,
                height=650, x_axis_label='MSD timepoint', y_axis_label='Deff')
            # Cycle through each particle chemistry and fill in Deffs
            # and avg_Deffs
            for title in columns2:
                single_Deff_list = []
                for i in range(0, len(temp2_msd)):
                    index = temp2_msd.index[i]
                    single_Deff_list.append(temp2_msd[title + ' geo'][index]/(
                        4*index**ALPHA))
                # Add particle-chemistry-specific Deff list to Deffs
                # dataframe
                Deffs[title] = single_Deff_list
                maxes.append(np.max(single_Deff_list))
                # Add geometric mean Deff to what will become avg_Deffs
                avg_Deffs_temp.append(scipy.stats.gmean(Deffs[title]))
                # Create a special bold/dashed line for the inputted
                # chemistry only, and generate the printed output
                if title == particle_chemistry:
                    p.line(
                        Deffs.index, Deffs[title], line_width=5,
                        line_dash=(15, 10), legend=title, line_color=(
                            np.random.randint(256), np.random.randint(256),
                            np.random.randint(256))
                        )
                    h = Histogram(Deffs[particle_chemistry], width=300,
                        height=250)
                    print particle_chemistry + ' Deff = ' + str(
                        scipy.stats.gmean(Deffs[title]))
                else:
                    p.line(
                        Deffs.index, Deffs[title], line_width=1, legend=title,
                        line_color=(
                            np.random.randint(256), np.random.randint(256),
                            np.random.randint(256))
                        )
            avg_Deffs['Deff'] = avg_Deffs_temp
            p.legend.label_text_font_size = '6pt'
            # The line plot x-axis range is calibrated to include all
            # of the desired data and the legend with no overlap
            p.x_range = Range1d(tmin, tmax + (tmax - tmin)/5)
            # The histogram x-axis is calibrated to remain at a
            # constant scale for each given tmin/tmax combination--this
            # gives a sense of scale for this particular histogram
            # within the possible Deff values for all the chemistries
            h.x_range = Range1d(0, np.max(maxes))
            f = hplot(h, p)
            show(f)
            return avg_Deffs
Exemplo n.º 30
0
def compute_hist_Deff(particle_chemistry, tmin, tmax):
    """
    Calculates and plots Deff in timepoint range for a given chemistry.

    This function trims the cleaned MSD pandas dataframe to the user-
    selected timepoint range, calculates a Deff from the mean MSD for
    each timepoint within the range, plots a histogram of the list of
    Deffs, and gives a geometric mean Deff value for the time range
    specified.  This is all within the specified particle chemistry.
    Note: tmin must be less than tmax.

    Inputs:
    particle_chemistry: a string matching the column title of the
    particle chemistry for which a Deff is to be plotted and calculated
    tmin: a float representing the minimum timepoint the user wishes to
    consider in the Deff calculation
    tmax: a float representing the maximum timepoint the user wishes to
    consider in the Deff calculation

    Outputs:
    A bokeh charts histogram of Deff values calculated from the
    particle chemistry's MSD of each timepoint within the range
    Deff: a single float representing the geometric mean Deff value for
    the timepoint range specified

    Side effects:
    The trimmed MSD dataset is appended (with a new column) to include
    the list of Deffs for the given particle chemistry.
    """
    # Verify time range validity
    if tmin < 0 or tmax > round(max(msd.index)):
        return "Error: input time range between 0 and your data's tmax"
    else:
        if tmin == 0:
            print 'Divide by 0 error: tmin=0 changed to tmin=0.01'
            tmin = 0.01
        # Trim out-of-time-range rows
        temp1_msd = msd[msd.index >= tmin]
        temp2_msd = temp1_msd[temp1_msd.index <= tmax]
        # Calculate Deffs for only the timepoints needed and add as a
        # new column
        Deff_list = []
        for i in range(0, len(temp2_msd)):
            index = temp2_msd.index[i]
            # Calculate Deff using the conventional relationship
            # between MSD and Deff
            Deff_list.append(temp2_msd[particle_chemistry + ' geo'][index]/(
                4*index**ALPHA))
        temp2_msd[particle_chemistry + ' Deff'] = Deff_list
        # Plot histogram and print mean Deff value
        output_file('Deffs_hist.html')
        p = Histogram(
            temp2_msd[particle_chemistry + ' Deff'], bins=15, legend=False)
        # Set range of x axis to reflect approximate range of all Deff
        # values
        p.x_range = Range1d(0, 0.015)
        show(p)
        # There's only one Deff column from this function: calculate
        # geometric mean Deff from that column
        Deff = scipy.stats.gmean(temp2_msd[particle_chemistry + ' Deff'])
        return Deff
Exemplo n.º 31
0
    def get_memory_hists(self, mode='overview'):
        """ Plot memory histogram in a row """
        access = self.__get_memory_access_types(mode)

        hists = []
        data_dfs = []

        col_cycle = []
        col_index = []

        for key, value in access.iteritems():
            sql_query = 'SELECT length FROM memory'
            sql_query += ' WHERE ' + value
            sql_query += ' ORDER by line'
            dataframe = pd.read_sql_query(sql_query, self.get_db())

            color = tm.get_random_color()

            col_sched = []
            col_location = []
            col_value = []
            col_type = []
            col_color = []

            try:
                # Some statistics
                mean = np.round_(dataframe["length"].mean(), 2)
                median = dataframe["length"].median()
                sum_len = dataframe["length"].sum()
                col_cycle.append(sum_len)
                col_index.append(key)

                # Plot histogram
                hist_title = key
                hist_title += ' / avg ' + str(mean)
                hist_title += ' / mid ' + str(median)
                plot_hist = Histogram(dataframe["length"].replace(0, np.nan),
                                      'length',
                                      bins=50,
                                      color=color,
                                      xlabel='Latency of instruction in cycle',
                                      ylabel='Count',
                                      title=hist_title)
            except ValueError:
                continue

            # Ignore NaN
            if mean == mean and median == median:
                # Insert mean
                col_sched.append(self.get_name_instruction_scheduler())
                col_location.append(key)
                col_value.append(mean)
                col_type.append('Mean')
                col_color.append(color)

                # Insert median
                col_sched.append(self.get_name_instruction_scheduler())
                col_location.append(key)
                col_value.append(median)
                col_type.append('Median')
                col_color.append(color)

                data = {'sched': col_sched,
                        'location': col_location,
                        'value': col_value,
                        'type': col_type,
                        'color': col_color}
                data_df = pd.DataFrame(data, index=col_location)
                data_dfs.append(data_df)

            hists.append(plot_hist)

        # Plot break down of cycles
        data = {'cycle': col_cycle}
        cycle_df = pd.DataFrame(data, index=col_index)
        pie_cycle = Donut(cycle_df.replace(0, np.nan),
                          title='Break down: cycles')
        hists.append(pie_cycle)

        info = {'hist': hists,
                'info': data_dfs}
        return info
Exemplo n.º 32
0
def simple_chart(request,counter_name):
	counter_len = len(Counter.objects.values())
	
	Date = [Counter.objects.values()[i]["pub_date"] for i in range(counter_len)]
	name = counter_name
	y_values = Counter.objects.values_list("counter_value",flat=True).filter(counter_name=counter_name)
	
	points = zip(Date,y_values)
	 
	ddict = OrderedDict({'Date':Date})
	#ddict[name] = y_values
	
	TOOLS="pan,wheel_zoom,box_zoom,reset,hover,save"	
	p = figure(width=1200, height=400, x_axis_type="datetime",tools=TOOLS,title=name+"'s Metrics" )	
	p.min_border_left = 100
	p.min_border_top = 50
	p.border_fill = 'whitesmoke'
	p.ygrid.band_fill_color = "#E6E6FA"	
	p.title_text_color = "olive"
	p.title_text_font = "times"
	p.title_text_font_style = "italic"	
	

	p.outline_line_width = 7
	p.outline_line_alpha = 0.3
	p.outline_line_color = "black"	
	
	
	source = ColumnDataSource(
       		 data=dict(
		
		rates = [slope(points[i][0].microsecond,points[i][1],points[i+1][0].microsecond,points[i+1][1]) for i in range(len(points)-1)]
		)       		 
   	 )	


	hover = p.select(dict(type=HoverTool))
	hover.point_policy = "follow_mouse"
	hover.tooltips = OrderedDict([
	("Counter Name",name),
   	("Rate of count","@rates c/us"),
	])
	
	p.line(Date,y_values,line_width=1,source=source)
	p.square(Date, y_values, fill_color=None, line_color="green",size=4)
	script1, div1 = components(p, CDN)

	hist = Histogram(list(y_values),bins=50,title='Histogram',color="#778899")
	hist.border_fill = 'whitesmoke'
	hist.background_fill = "beige"
	
	script2, div2 = components(hist, CDN)
	
	area = Area(list(y_values),title="CDF")
	area.border_fill ="whitesmoke"
	area.background_fill = "#191970"
		
	script3, div3 = components(area,CDN)

	


	context = RequestContext(request,{"the_script1":script1, "the_div1":div1,"the_script2":script2,"the_div2":div2,"the_script3":script3,"the_div3":div3})	

	return render(request, "counters_app/simple_bokeh.html",context)
Exemplo n.º 33
0
from bokeh.charts import Histogram, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Histogram(df, values='mpg', bins=50, title="MPG Distribution (50 bins)")

output_file("histogram_bins.html")

show(p)
Exemplo n.º 34
0
from bokeh.charts import Histogram, output_file, show
from bokeh.layouts import row
from bokeh.sampledata.autompg import autompg as df

hist = Histogram(df, values='mpg', title="Auto MPG Histogram", plot_width=400)
hist2 = Histogram(df, values='mpg', label='cyl', color='cyl', legend='top_right',
                  title="MPG Histogram by Cylinder Count", plot_width=400)

output_file('hist.html')
show(row(hist, hist2))
Exemplo n.º 35
0
from bokeh.charts import Histogram, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Histogram(df['mpg'], title="MPG Distribution")

output_file("histogram.html", )

show(p)
Exemplo n.º 36
0
# ch29.py

# ref:
# http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html#color-groups

# However, the color parameter can also be used to group the data. If
# the value of the color parameter is one of the DataFrame column
# names, the data is first grouped by this column, and a histogram is
# generated for each group. Each histogram is automatically colored
# differently, and a legend displayed:

from bokeh.charts import Histogram, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Histogram(df, values='hp', color='cyl',
              title="HP Distribution (color grouped by CYL)",
              legend='top_right')

output_file("/tmp/ch29.html")

show(p)


Exemplo n.º 37
0
Arquivo: main.py Projeto: chakas/bokeh
def get_histogram(t):
    t1, t2 = ticker1.value, ticker2.value
    data = get_data(t1, t2)
    h = Histogram(data[[t]], values=t)
    h.toolbar_location = None
    return h