コード例 #1
0
    def __init__(self,
                 df,
                 params=[],
                 logify=False,
                 output='notebook',
                 notebook_url="http://localhost:8888",
                 **kwargs):
        self.df = df
        self.params = params
        self.logify = logify
        self.kwargs = kwargs

        if output == 'notebook':
            reset_output()
            output_notebook()
            show(self.modify_doc, notebook_url=notebook_url)
        else:
            reset_output()
            server = Server({'/': self.modify_doc})
            server.start()
            try:
                server = Server({'/': self.modify_doc})
                server.run_until_shutdown()
            except:
                pass
                #print("Server running")
            server.show("/")
            self.server = server
コード例 #2
0
 def plot_candles(self):
     df = self.df[450:]
     df["date"] = df["Open_time"]
     df["date"] = pd.to_datetime(self.df['date'], unit='ms')
     inc = df.Close > df.Open
     dec = df.Open > df.Close
     w = 12 * 60 * 60 * 1000  # half day in ms
     TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
     p = figure(x_axis_type="datetime",
                tools=TOOLS,
                plot_width=1000,
                title="BITCOIN Candlestick")
     p.xaxis.major_label_orientation = pi / 4
     p.grid.grid_line_alpha = 0.3
     p.segment(df.date, df.High, df.date, df.Low, color="black")
     p.vbar(df.date[inc],
            w,
            df.Open[inc],
            df.Close[inc],
            fill_color="#006400",
            line_color="black")
     p.vbar(df.date[dec],
            w,
            df.Open[dec],
            df.Close[dec],
            fill_color="#F2583E",
            line_color="black")
     output_notebook()
     return p
コード例 #3
0
ファイル: status_monitor.py プロジェクト: coobas/distributed
    def __init__(self, addr=None, interval=1000.00, loop=None):
        if addr is None:
            scheduler = default_executor().scheduler
            if isinstance(scheduler, rpc):
                addr = (scheduler.ip, 9786)
            elif isinstance(scheduler, Scheduler):
                addr = ('127.0.0.1', scheduler.services['http'].port)
        self.addr = addr
        self.interval = interval

        self.display_notebook = False

        if is_kernel() and not curstate().notebook:
            output_notebook()
            assert curstate().notebook

        self.task_source, self.task_table = task_table_plot()
        self.worker_source, self.worker_table = worker_table_plot()

        self.output = vplot(self.worker_table, self.task_table)

        self.client = AsyncHTTPClient()

        self.loop = loop or IOLoop.current()
        self.loop.add_callback(self.update)
        self._pc = PeriodicCallback(self.update, self.interval, io_loop=self.loop)
        self._pc.start()
コード例 #4
0
    def plot_cross_points(self):
        self.eval_boillinger_bands()

        self.candles['up_cross'] = np.where(
            (self.candles['Close'] >= self.candles['Upper Band']),
            self.candles['Close'], None)
        self.candles['down_cross'] = np.where(
            (self.candles['Close'] <= self.candles['Lower Band']),
            self.candles['Close'], None)

        p = self.configure_plot(self.candles)
        p.circle(self.candles.date,
                 self.candles['up_cross'],
                 size=5,
                 color="red",
                 alpha=1,
                 legend="Up cross")
        p.circle(self.candles.date,
                 self.candles['down_cross'],
                 size=5,
                 color="green",
                 alpha=1,
                 legend="Down cross")
        output_notebook()
        return p
コード例 #5
0
def viz_zone_stat(input_shapefile,poly,uid):
    
    try:
        os.remove('ndvi_stats.html')
    
    except OSError:
        pass
    
    palette.reverse()
    output_notebook()
    output_file('ndvi_stats1.html')
    props = OrderedDict()
    with fiona.open(input_shapefile, 'r') as polys:
        for i in polys:
            prop = OrderedDict()
            prop[i['properties'].get(uid)] = {}
            prop[i['properties'].get(uid)].update({ stat : val  for stat , val in i['properties'].items()})
            props.update(prop)
    
    px = []
    py = []
    for i in poly:
        x,y = i.exterior.xy
        x=x.tolist()
        y=y.tolist()
        px.append(x)
        py.append(y)
    
    polyID = []
    mndvi = []
    std_ndvi= []
    color_mapper = LogColorMapper(palette=palette)
    for key in props:
        polyID.append(props[key][uid])
        mndvi.append(props[key]['mean']) 
        std_ndvi.append(props[key]['std'])


    source = ColumnDataSource(data=OrderedDict(
        tid=polyID,mndvi=mndvi,stdndvi=std_ndvi,x=px,y=py))

    TOOLS = "pan,wheel_zoom,reset,hover,save"

    TOOLTIPS=[
       ((uid), "@tid"), 
        ("Mean NDVI", "@mndvi"), 
        ("Std. NDVI", "@stdndvi")]


    p = figure(plot_width=500, plot_height=500,title="Zonal Statistics")
    
    #p.hover.point_policy = "follow_mouse"
    
    "fill color", "$color[hex, swatch]:fill_color"
    plots = p.patches('x', 'y', source=source,
              fill_color={'field': 'mndvi', 'transform': color_mapper},
              fill_alpha=0.7, line_color="black", line_width=0.5)

    p.add_tools(HoverTool(tooltips=TOOLTIPS, mode='mouse'))
    show(p)
コード例 #6
0
    def __init__(self, addr=None, interval=1.00):
        if addr is None:
            scheduler = default_executor().scheduler
            if isinstance(scheduler, rpc):
                addr = (scheduler.ip, scheduler.port)
            elif isinstance(scheduler, Scheduler):
                addr = ('127.0.0.1', scheduler.port)

        self.cds = ColumnDataSource({k: []
            for k in ['host', 'cpu', 'memory',
                      'zero', 'left', 'mid', 'right']})

        self.display_notebook = False


        self.figure = figure(height=200, width=800, y_range=(0, 100))
        self.figure.logo = None

        cpu = self.figure.quad(legend='cpu', left='left', right='mid',
                         bottom='zero', top='cpu', source=self.cds,
                         color=(0, 0, 255, 0.5))
        memory = self.figure.quad(legend='memory', left='mid', right='right',
                         bottom='zero', top='memory', source=self.cds,
                         color=(255, 0, 0, 0.5))

        self.figure.add_tools(HoverTool(renderers=[cpu, memory],
                                        tooltips=[("host", "@host"),
                                                  ("cpu", "@cpu"),
                                                  ("memory", "@memory")]))

        self.future = self.update(addr, interval)

        if is_kernel() and not curstate().notebook:
            output_notebook()
            assert curstate().notebook
コード例 #7
0
    def __init__(self, addr=None, interval=1000.00, loop=None):
        if addr is None:
            scheduler = default_executor().scheduler
            if isinstance(scheduler, rpc):
                addr = (scheduler.ip, 9786)
            elif isinstance(scheduler, Scheduler):
                addr = ('127.0.0.1', scheduler.services['http'].port)
        self.addr = addr
        self.interval = interval

        self.display_notebook = False

        if is_kernel() and not curstate().notebook:
            output_notebook()
            assert curstate().notebook

        self.task_source, self.task_table = task_table_plot()
        self.worker_source, self.worker_table = worker_table_plot()

        self.output = vplot(self.worker_table, self.task_table)

        self.client = AsyncHTTPClient()

        self.loop = loop or IOLoop.current()
        self.loop.add_callback(self.update)
        self._pc = PeriodicCallback(self.update, self.interval, io_loop=self.loop)
        self._pc.start()
コード例 #8
0
def some_activities(constraint):
    f'''
    # Some Activities: {constraint}
    '''
    '''
    $contents
    '''
    '''
    ## Build Maps
    
    Loop over activities, retrieve data, and construct maps. 
    '''

    s = session('-v2')
    maps = [
        map_thumbnail(100, 120, data)
        for data in (activity_statistics(s,
                                         SPHERICAL_MERCATOR_X,
                                         SPHERICAL_MERCATOR_Y,
                                         ACTIVE_DISTANCE,
                                         TOTAL_CLIMB,
                                         activity_journal=aj)
                     for aj in constrained_activities(s, constraint))
        if len(data[SPHERICAL_MERCATOR_X].dropna()) > 10
    ]
    print(f'Found {len(maps)} activities')
    '''
    ## Display Maps
    '''

    output_notebook()
    show(tile(maps, 8))
コード例 #9
0
def init_bokeh_plot(umap_df):

    bplt.output_notebook()

    datasource = bokeh.models.ColumnDataSource(umap_df)
    color_mapping = bokeh.models.CategoricalColorMapper(
        factors=["sns", "goat"], palette=bokeh.palettes.Spectral10)

    plot_figure = bplt.figure(title='UMAP projection VAE latent',
                              plot_width=1000,
                              plot_height=1000,
                              tools=('pan, wheel_zoom, reset'))

    plot_figure.add_tools(
        bokeh.models.HoverTool(tooltips="""
    <div>
        <div>
            <img src='@image' style='float: left; margin: 5px 5px 5px 5px'/>
        </div>
        <div>
            <span style='font-size: 14px'>@fname</span>
            <span style='font-size: 14px'>@loss</span>
        </div>
    </div>
    """))

    plot_figure.circle('x',
                       'y',
                       source=datasource,
                       color=dict(field='db', transform=color_mapping),
                       line_alpha=0.6,
                       fill_alpha=0.6,
                       size=4)

    return plot_figure
コード例 #10
0
ファイル: Basic_Module.py プロジェクト: drumcap/vanillaPython
def Make_TSNE2(n_component, model, wv, limit):
    from sklearn.manifold import TSNE
    import matplotlib.pyplot as plt
    import pandas as pd
    from tqdm import tqdm
    import bokeh.plotting as bp
    from bokeh.models import HoverTool, BoxSelectTool
    from bokeh.plotting import figure, show, output_notebook

    output_notebook()
    plot_tfidf = bp.figure(
        plot_width=500,
        plot_height=500,
        title="A map of word vectors",
        tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave",
        x_axis_type=None,
        y_axis_type=None,
        min_border=1)

    word_vectors = [
        model[w] for w in tqdm(list(model.wv.vocab.keys())[:limit])
    ]

    tsne_model = TSNE(n_components=n_component, verbose=1, random_state=0)
    tsne_w2v = tsne_model.fit_transform(word_vectors)
    # putting everything in a dataframe
    tsne_df = pd.DataFrame(tsne_w2v, columns=['x', 'y'])
    tsne_df['words'] = list(model.wv.vocab.keys())[:limit]

    # plotting. the corresponding word appears when you hover on the data point.
    plot_tfidf.scatter(x='x', y='y', source=tsne_df)
    hover = plot_tfidf.select(dict(type=HoverTool))
    hover.tooltips = {"word": "@words"}
    show(plot_tfidf)
コード例 #11
0
def Return_Benchmark(result):	
    '''Plot algorithm_period_return and benchmark_period_return.
    Change output_notebook() to get a file output.

    Parameters
    ----------
    result is the result passed into analyze in a zipline algorithm.   
    '''
    rtn = list(result.algorithm_period_return)
    rtn_bm = list(result.benchmark_period_return)
    dates = list(result.index)
    
    output_notebook()
    
    p = figure(width=800, height=350, x_axis_type="datetime")
    p.line(dates, rtn_bm, color='darkgrey', line_dash='dashed', legend='Benchmark')
    p.line(dates, rtn, color='navy', legend='Algorithm')
    p.legend.location = "top_left"
    p.grid.grid_line_alpha=0
    p.xaxis.axis_label = 'Date'
    p.yaxis.axis_label = 'Return'
    p.ygrid.band_fill_color="olive"
    p.ygrid.band_fill_alpha = 0.1
    
    show(p)
コード例 #12
0
def explore_venues():

    color_palette = ['#ea4335', '#fbbc05', '#34a853', '#673ab7']
    categories = ['socializing', 'career-business', 'tech', 'music']

    city_lat, city_lon = (42.361145, -71.057083)

    plot_data = pd.read_pickle('boston_venue_category')
    plot_data['coords_x'] = plot_data['lon'].apply(lambda x: h.merc_x(x))
    plot_data['coords_y'] = plot_data['lat'].apply(lambda x: h.merc_y(x))

    X_range = (h.merc_x(city_lon) - 9000, h.merc_x(city_lon) + 3000)
    Y_range = (h.merc_y(city_lat) - 5000, h.merc_y(city_lat) + 5000)

    p = figure(x_range=X_range,
               y_range=Y_range,
               x_axis_type="mercator",
               y_axis_type="mercator")

    # load map
    p.add_tile(CARTODBPOSITRON)

    # add venues
    for ctg, cp in zip(categories, color_palette):
        p.circle(x=plot_data.loc[plot_data.category == ctg, 'coords_x'],
                 y=plot_data.loc[plot_data.category == ctg, 'coords_y'],
                 line_alpha=0.05,
                 fill_color=cp,
                 size=np.log(plot_data.loc[plot_data.category == ctg,
                                           'sum(host)']) * 2.5,
                 legend=ctg,
                 fill_alpha=0.3)
    output_notebook()
    show(p)
コード例 #13
0
ファイル: _SP3.py プロジェクト: hhebb/HTM
    def viz_activeCol(self):

        output_notebook()

        N = self.columnCount
        img = np.zeros([1, N, 4], dtype=np.uint8)

        maxOverlap = np.sort(self.overlapped).copy()[-1]

        for i in range(N):
            if (self.activeColumns[i]):
                img[0, i, 0:3] = 0  # r

            else:
                img[0, i, 0:3] = 255  # r

            img[0, i, 3] = np.sqrt(self.overlapped[i] / maxOverlap) * 255  # a
        #
        p = figure(plot_width=1000, plot_height=100)
        p.image_rgba(image=[img], x=[0], y=[0], dw=[self.columnCount], dh=[1])
        show(p)

        idx = []
        for i in range((self.columnCount)):
            if (self.activeColumns[i] == 1):
                idx.append(i)
        print("active columns : {} \ncount : {}".format(
            idx, np.count_nonzero(self.activeColumns)))
コード例 #14
0
def notebook_plot(x_key, y_keys, **kwargs):
    r"""Live plot log entries in the current notebook.

    Parameters
    ----------
    x_key : str
        The key in the serialized JSON object that contains the x-axis
        value.
    y_key : list of str
        See `x_key`.
    \*\*kwargs
        Connection parameters passed to the `connect` function.

    """
    subscriber, sequence, x, y = get_socket(x_key, y_keys, **kwargs)
    output_notebook()

    fig = figure()
    plot = fig.line(x, y)

    handle = show(fig, notebook_handle=True)
    push_notebook(handle=handle)

    while True:
        update(x_key, y_keys, sequence, subscriber, plot)
        push_notebook(handle=handle)
コード例 #15
0
def all_group_activities(start, finish, activity_group):
    f'''
    # All Activities for {activity_group}: {start.split()[0]} - {finish.split()[0]}
    '''
    '''
    $contents
    '''
    '''
    ## Build Maps
    
    Loop over activities, retrieve data, and construct maps. 
    '''

    s = session('-v2')
    maps = [
        map_thumbnail(100, 120, data)
        for data in (Statistics(s, activity_journal=aj).by_name(
            ActivityReader, N.SPHERICAL_MERCATOR_X, N.SPHERICAL_MERCATOR_Y
        ).by_name(ActivityCalculator, N.ACTIVE_DISTANCE, N.ACTIVE_TIME).df
                     for aj in s.query(ActivityJournal).filter(
                         ActivityJournal.start >= local_date_to_time(start),
                         ActivityJournal.start < local_date_to_time(finish),
                         ActivityJournal.activity_group_id ==
                         ActivityGroup.from_name(s, activity_group)).order_by(
                             ActivityJournal.start.desc()).all())
        if len(data[N.SPHERICAL_MERCATOR_X].dropna()) > 10
    ]
    print(f'Found {len(maps)} activities')
    '''
    ## Display Maps
    '''

    output_notebook()
    show(htile(maps, 8))
コード例 #16
0
def show_error_vs_real_train(results_df_train):

    source = ColumnDataSource(results_df_train)

    # Creation d'un figure interactive bokeh affichant l'erreur vs la valeur reelle
    p = figure(
        title="Error vs real",
        tools='pan, box_zoom, undo, reset, hover',
        tooltips=
        [("index", "@index"), ("prediction", "@prediction{0,0}"),
         ("real", "@real{0,0}"),
         ('Building surface', '@PropertyGFATotal{0,0}'),
         ('Primary usage',
          '@LargestPropertyUseType, @LargestPropertyUseTypeGFA{0,0}'),
         ('Second usage',
          '@SecondLargestPropertyUseType, @SecondLargestPropertyUseTypeGFA{0,0}'
          ),
         ('Third usage',
          '@ThirdLargestPropertyUseType, @ThirdLargestPropertyUseTypeGFA{0,0}')
         ])

    p.xaxis.axis_label = 'Real'
    p.yaxis.axis_label = '% Error'
    p.circle("real", '%_error', source=source)

    output_notebook()
    show(p)
コード例 #17
0
ファイル: plotting.py プロジェクト: ceb8/MovingMast
def notebook_bokeh(stcs):
    patch_xs = parse_s_region(stcs)['ra']
    patch_ys = parse_s_region(stcs)['dec']

    p = figure(plot_width=700,
               x_axis_label="RA (deg)",
               y_axis_label="Dec (deg)")

    data = {'x': [patch_xs], 'y': [patch_ys]}
    p.patches('x',
              'y',
              source=data,
              fill_alpha=0.1,
              line_color="black",
              line_width=0.5)

    p.add_layout(
        Arrow(end=VeeHead(line_color="black", line_width=1),
              line_width=2,
              x_start=patch_xs[0],
              y_start=patch_ys[0],
              x_end=patch_xs[1],
              y_end=patch_ys[1]))

    p.y_range.flipped = True

    output_notebook()
    show(p)
コード例 #18
0
def plot_flare_bokeh(time, flux_pca, flux = None, flux_type ="",width_fig = 900, height_fig = 500, title=""):
    # output form
    reset_output()

    output_notebook()

    TOOLTIPS = [
        ("index", "$index"),
        ("(x,y)", "($x, $y)"),
    ]

    # graph setting
    p = figure(tooltips=TOOLTIPS, title=title, x_axis_label="Time", y_axis_label="Flux",  plot_width = width_fig, plot_height=height_fig)

    # main body for  plotting
    #if flux is not None:

        #p.circle(time, flux, legend="raw" + "(%s)" % flux_type, color="red")
        #p.line(time, flux, legend="raw"+ "(%s)" % flux_type, color="red")
    p.circle(time, flux_pca, color="black")
    p.line(time, flux_pca, color="black")

    #p.add_layout(p.legend[0], "right") # 凡例をグラフの外に出す(右側)

    # Hide legend if you click
    #p.legend.click_policy = "hide"

    # Output format (svg or png)
    p.output_backend = "svg"
    
    # Show
    show(p)
コード例 #19
0
def plot_word_vectors(w2v):
    """
    Scatter plot of word vectors
    
    Parameters
    ----------
    w2v : gensim.Word2Vec
        word2vec model
    """
    output_notebook()
    plot_tools = "pan,wheel_zoom,box_zoom,reset,hover,previewsave"
    plot_tfidf = bp.figure(plot_width=700,
                           plot_height=600,
                           title="A map of the word vectors",
                           tools=plot_tools,
                           x_axis_type=None,
                           y_axis_type=None,
                           min_border=1)

    word_vectors = [w2v.wv[w] for w in w2v.wv.vocab.keys()]

    tsne = TSNE(n_components=2, verbose=1, random_state=0)
    tsne_w2v = tsne.fit_transform(word_vectors)

    tsne_df = pd.DataFrame(tsne_w2v, columns=['x', 'y'])
    tsne_df['words'] = w2v.wv.vocab.keys()

    plot_tfidf.scatter(x='x', y='y', source=tsne_df)
    hover = plot_tfidf.select(dict(type=HoverTool))
    hover.tooltips = {"word": "@words"}
    show(plot_tfidf)
コード例 #20
0
def all_activities(start: to_date, finish: to_date):
    f'''
    # All Activities: {start.split()[0]} - {finish.split()[0]}
    '''
    '''
    $contents
    '''
    '''
    ## Build Maps
    
    Loop over activities, retrieve data, and construct maps. 
    '''

    s = session('-v2')
    maps = [
        map_thumbnail(100, 120, data) for data in (
            activity_statistics(s,
                                SPHERICAL_MERCATOR_X,
                                SPHERICAL_MERCATOR_Y,
                                ACTIVE_DISTANCE,
                                ACTIVE_TIME,
                                activity_journal=aj)
            for aj in s.query(ActivityJournal).filter(
                ActivityJournal.start >= local_date_to_time(start),
                ActivityJournal.start < local_date_to_time(finish)).all())
        if len(data[SPHERICAL_MERCATOR_X].dropna()) > 10
    ]
    print(f'Found {len(maps)} activities')
    '''
    ## Display Maps
    '''

    output_notebook()
    show(tile(maps, 8))
コード例 #21
0
    def visualize_kmeans(self):
        kmeans = self.run_k_means
        # output to static HTML file
        output_notebook()

        TOOLTIPS = [
            ("index", "$index"),
            ("(x,y)", "($x, $y)")
        ]

        p1 = figure(plot_width=500, plot_height=500, tooltips=TOOLTIPS,)

        # Get the number of colors we'll need for the plot.
        colors = d3["Category20"][len(kmeans[0].unique())]

        # Create a map between factor and color.
        colormap = {i: colors[i] for i in kmeans[0].unique()}

        # Create a list of colors for each value that we will be looking at.
        colors = [colormap[x] for x in kmeans[0]]
        # add a square renderer with a size, color, and alpha
        p1.circle(self._principalDf['principal component 1'],self._principalDf['principal component 2'], size=2, color=colors, alpha=0.7)

        # show the results
        show(p1)
コード例 #22
0
def similar_activities(local_time: to_date, activity_group_name):

    f'''
    # Similar Activities: {local_time.split()[0]}
    '''

    '''
    $contents
    '''

    '''
    ## Build Maps
    
    Loop over activities, retrieve data, and construct maps. 
    '''

    s = session('-v2')

    maps = [map_thumbnail(100, 120, data)
            for data in (activity_statistics(s, SPHERICAL_MERCATOR_X, SPHERICAL_MERCATOR_Y,
                                             activity_journal_id=similar[0].id).resample('1min').mean()
                         for similar in nearby_activities(s, local_time=local_time,
                                                          activity_group_name=activity_group_name))
            if len(data.dropna()) > 10]

    print(f'Found {len(maps)} activities')

    '''
    ## Display Maps
    '''

    output_notebook()
    show(tile(maps, 8))
コード例 #23
0
def plot_vertical():
    """
    Plot of vertical jump by yardage with tabs for each position.

    Calls:
    make_dfs(), rb(), wr(), qb()
    """
    dfRB, dfWR, dfQB = make_dfs()
    dfRB = dfRB[dfRB.vertical > 0]
    dfWR = dfWR[dfWR.vertical > 0]
    # Remove Alex Smith (incorrect measurement)
    dfQB = dfQB[dfQB.vertical > 20]

    output_notebook()
#    output_file('40yd.html')
    tab1 = rb('vertical', 'Vertical Jump (in)',
              'RB: Total Yards by Vertical Jump', 'Vertical Jump (in)',
              dfRB, dfWR, dfQB)
    tab2 = wr('vertical', 'Vertical Jump (in)',
              'WR: Total Yards by Vertical Jump', 'Vertical Jump (in)',
              dfRB, dfWR, dfQB)
    tab3 = qb('vertical', 'Vertical Jump (in)',
              'QB: Total Yards by Vertical Jump',
              'Vertical Jump (in)', dfRB, dfWR, dfQB)
    tabs = Tabs(tabs=[tab1, tab2, tab3])
    show(tabs)
コード例 #24
0
ファイル: visualizers.py プロジェクト: KirkVM/kdatapack
def plot_eblanks(df, xcolname='econc_mgmL', ycolname='measurement'):
    df['strdate'] = df.expdate.apply(str)
    #    sdf_dict={}
    cds_dict = {}
    for egroup in df.groupby(by=['ename', 'expdate']):
        grpname = ''.join([str(x) + ' ' for x in egroup[0]])[:-1]
        cds_dict[grpname] = ColumnDataSource.from_df(
            egroup[1])  #df[df.expdate==expdate])#sdf_dict[expdate])

    p = figure(plot_width=800)
    ht=HoverTool(tooltips=[('enzyme','@ename'),('M','@econc_molar'),('date','@strdate'),('plateid','@plateid'),\
                            ('thing','@predvlp_dlnfactor')])
    for dnum, grpname in enumerate(cds_dict):
        didx = dnum % 10
        p.circle(xcolname,
                 ycolname,
                 legend=grpname,
                 size=10,
                 color=palettes.Category20[20][didx],
                 source=cds_dict[grpname])
    p.tools = [ht, BoxZoomTool(), ResetTool()]
    #    p.tools=[ht,"box_zoom"]
    p.x_range = Range1d(-0.1, 4.5)
    output_notebook()
    show(p)
コード例 #25
0
def show_pred_vs_real_test(results_df_test):

    source = ColumnDataSource(results_df_test)

    # Creation d'un figure interactive bokeh affichant la valeur predite vs la valeur reelle
    p = figure(
        title="Prediction vs real",
        tools='pan, box_zoom, undo, reset, hover',
        tooltips=
        [("index", "@index"), ("prediction", "@prediction{0,0}"),
         ("real", "@real{0,0}"),
         ('Primary usage',
          '@LargestPropertyUseType, @LargestPropertyUseTypeGFA{0,0}'),
         ('Second usage',
          '@SecondLargestPropertyUseType, @SecondLargestPropertyUseTypeGFA{0,0}'
          ),
         ('Third usage',
          '@ThirdLargestPropertyUseType, @ThirdLargestPropertyUseTypeGFA{0,0}')
         ])
    p.xaxis.axis_label = 'Real'
    p.yaxis.axis_label = 'Prediction'
    p.circle("real", "prediction", source=source)
    p.line("real", "real", color='orange', source=source)
    output_notebook()
    show(p)
コード例 #26
0
ファイル: _misc.py プロジェクト: ywang542/para-atm
def plot_trajectory(df, output_file=None, output_notebook=False):
    """Plot scenario trajectory to static html and open browser
    
    Parameters
    ----------
    df : DataFrame
        DataFrame containing a scenario with 'latitude', 'longitude',
        'heading', and 'callsign' columns
    output_file : str
        Output file for html (if None, use bokeh default)
    output_notebook : bool
        If True, output to jupyter notebook
    """
    if output_file is not None:
        bkplot.output_file(output_file)
    elif output_notebook:
        bkplot.output_notebook()

    p = bkplot.figure(x_axis_type='mercator', y_axis_type='mercator')
    tile_provider = get_provider(Vendors.CARTODBPOSITRON)
    p.add_tile(tile_provider)

    df_plot = df[['latitude','longitude','heading','callsign']].copy()
    df_plot['longitude'], df_plot['latitude'] = _merc(df_plot['latitude'].values, df_plot['longitude'].values)

    points = p.triangle(x='longitude', y='latitude', angle='heading', angle_units='deg', alpha=0.5, source=df_plot)

    callsigns = df_plot['callsign'].unique()
    points.glyph.fill_color = bk.transform.factor_cmap('callsign', palette=bk.palettes.Category10[10], factors=callsigns)
    points.glyph.line_color = bk.transform.factor_cmap('callsign', palette=bk.palettes.Category10[10], factors=callsigns)

    bkplot.show(p)
コード例 #27
0
ファイル: bkcorner.py プロジェクト: peterrwi/bokehnotes
    def __init__(self,
                 df,
                 params=[],
                 trim_factor=1,
                 logify=False,
                 output='notebook',
                 port=5006,
                 notebook_url="http://localhost:8888",
                 **kwargs):
        self.df = df.iloc[::trim_factor].reset_index(drop=True)
        self.params = params
        self.logify = logify
        self.kwargs = kwargs

        if output == 'notebook':
            reset_output()
            output_notebook()
            show(self.modify_doc, notebook_url=notebook_url)
        elif output == 'server':
            reset_output()
            server = Server({'/': self.modify_doc}, port=port)
            server.start()
            try:
                server.run_until_shutdown()
            except:
                print("Server already running")
            self.server = server
コード例 #28
0
ファイル: plot.py プロジェクト: nke001/mimir
def notebook_plot(x_key, y_key, **kwargs):
    r"""Live plot log entries in the current notebook.

    Parameters
    ----------
    x_key : str
        The key in the serialized JSON object that contains the x-axis
        value.
    y_key : str
        See `x_key`.
    \*\*kwargs
        Connection parameters passed to the `connect` function.

    """
    subscriber, sequence, x, y = connect(x_key, y_key, **kwargs)
    session = push_session(curdoc())
    output_notebook()

    fig = figure()
    plot = fig.line(x, y)

    show(fig)

    def notebook_update():
        update(x_key, y_key, sequence, subscriber, plot)
        push_notebook()

    curdoc().add_periodic_callback(notebook_update, 50)

    session.loop_until_closed()
コード例 #29
0
def bubble_scatter_plot(df, x, y, z, norm=1.6):
    """
    bubble plot showing y vs x
    with z as the size of bubbles

    :param: df, dataset
    :type: pandas dataframe
    :param: x, attribute to be on x axis
    :type: str
    :param: y, attribute to be on y axis
    :type: str
    :param: z, attribute to be size of bubbles
    :type: str

    """
    assert isinstance(df, pd.DataFrame), 'Input must be a dataframe!'
    assert isinstance(x, str), 'X-axis must be a string!'
    assert isinstance(y, str), 'Y-axis must be a string!'
    assert isinstance(z, str), 'Z-axis must be a string!'
    assert x in att, 'Not an attribute!'
    assert y in att, 'Not an attribute!'
    assert z in att, 'Not an attribute!'
    assert isinstance(norm, float)

    output_notebook()

    df_4e = df
    #filter
    df_4e = df_4e[[x, y, z]]

    #group by rating
    grouped = df_4e.set_index(x).groupby(x)
    df_4e = grouped.agg([np.nanmean])

    #plot
    p = figure(title="%s vs %s vs %s" % (z, y, x),
               plot_width=800,
               plot_height=400)
    p.grid.grid_line_color = None
    p.background_fill_color = "white"
    #bubbles
    p.scatter(df[x],
              df[y],
              marker='o',
              size=(df[z] - 18) * norm,
              color="orange",
              alpha=0.8)
    #mean scatter
    p.scatter(df_4e.index,
              df_4e[y]['nanmean'],
              marker='o',
              size=15,
              color="red",
              alpha=0.9)
    p.xaxis.axis_label = '%s' % x
    p.yaxis.axis_label = '%s' % y

    #legend
    p
    return p
コード例 #30
0
ファイル: draw.py プロジェクト: feng1918/qfeng
def plot_bokeh_candle_dochl(date, p_open, close, high, low, symbol):
    COLORUP = 'red'
    COLORDOWN = 'green'
    bp.output_notebook()

    p = bp.figure(x_axis_type="datetime", plot_width=840, title=symbol)
    p.xaxis.major_label_orientation = pi / 4
    p.grid.grid_line_alpha = 0.3

    w = 24 * 60 * 60 * 1000
    mids = (p_open + close) / 2
    spans = abs(close - p_open)

    inc = close > p_open
    dec = p_open > close

    p.segment(date.to_datetime(), high, date.to_datetime(), low, color="black")
    p.rect(date.to_datetime()[inc],
           mids[inc],
           w,
           spans[inc],
           fill_color=COLORUP,
           line_color=COLORUP)
    p.rect(date.to_datetime()[dec],
           mids[dec],
           w,
           spans[dec],
           fill_color=COLORDOWN,
           line_color=COLORDOWN)
    bp.show(p)
コード例 #31
0
def plot_vertical():
    """
    Plot of vertical jump by yardage with tabs for each position.

    Calls:
    make_dfs(), rb(), wr(), qb()
    """
    dfRB, dfWR, dfQB = make_dfs()
    dfRB = dfRB[dfRB.vertical > 0]
    dfWR = dfWR[dfWR.vertical > 0]
    dfQB = dfQB[dfQB.vertical > 20]  #Remove Alex Smith (incorrect measurement)

    output_notebook()
    #    output_file('40yd.html')
    tab1 = rb('vertical', 'Vertical Jump (in)',
              'RB: Total Yards by Vertical Jump', 'Vertical Jump (in)', dfRB,
              dfWR, dfQB)
    tab2 = wr('vertical', 'Vertical Jump (in)',
              'WR: Total Yards by Vertical Jump', 'Vertical Jump (in)', dfRB,
              dfWR, dfQB)
    tab3 = qb('vertical', 'Vertical Jump (in)',
              'QB: Total Yards by Vertical Jump', 'Vertical Jump (in)', dfRB,
              dfWR, dfQB)
    tabs = Tabs(tabs=[tab1, tab2, tab3])
    show(tabs)
コード例 #32
0
ファイル: Plotting.py プロジェクト: weiyangliu/QGL
def output_notebook(local=True, suppress_warnings=False):
    if suppress_warnings:
        warnings.simplefilter("ignore", BokehUserWarning)
    if local:
        bk.output_notebook(resources=INLINE)
    else:
        bk.output_notebook()
コード例 #33
0
    def plot_targets(self):
        TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
        p = figure(x_axis_type="datetime",
                   tools=TOOLS,
                   plot_width=1000,
                   title="Target Chart")
        p.xaxis.major_label_orientation = pi / 4
        p.grid.grid_line_alpha = 0.3

        p.line(self.candles.date, self.candles.Close, line_color="black")

        p.circle(self.candles.date,
                 self.candles['sell'],
                 size=5,
                 color="red",
                 alpha=1,
                 legend='buy')
        p.circle(self.candles.date,
                 self.candles['buy'],
                 size=5,
                 color="green",
                 alpha=1,
                 legend='sell')
        p.circle(self.candles.date,
                 self.candles['hold'],
                 size=2,
                 color="blue",
                 alpha=1,
                 legend='hold')
        output_notebook()
        return p
コード例 #34
0
ファイル: plotting.py プロジェクト: arogozhnikov/rep
    def plot_bokeh(self, xlim=None, ylim=None, title=None, figsize=None,
                   xlabel=None, ylabel=None, fontsize=None, show_legend=True):

        """
        Plot data using bokeh library. Use show() method for bokeh to see result.

        :param xlim: x-axis range
        :param ylim: y-axis range
        :type xlim: None or tuple(x_min, x_max)
        :type ylim: None or tuple(y_min, y_max)
        :param title: title
        :type title: None or str
        :param figsize: figure size
        :type figsize: None or tuple(weight, height)
        :param xlabel: x-axis name
        :type xlabel: None or str
        :param ylabel: y-axis name
        :type ylabel: None or str
        :param fontsize: font size
        :type fontsize: None or int
        :param bool show_legend: show or not labels for plots
        """
        global _COLOR_CYCLE_BOKEH
        global _BOKEH_OUTPUT_NOTEBOOK_ACTIVATED
        import bokeh.plotting as bkh
        from bokeh.models import Range1d
        from bokeh.core.properties import value

        figsize = self.figsize if figsize is None else figsize
        xlabel = self.xlabel if xlabel is None else xlabel
        ylabel = self.ylabel if ylabel is None else ylabel
        title = self.title if title is None else title
        xlim = self.xlim if xlim is None else xlim
        ylim = self.ylim if ylim is None else ylim
        fontsize = self.fontsize if fontsize is None else fontsize
        self.fontsize_ = fontsize
        self.show_legend_ = show_legend

        figsize = (figsize[0] * self.BOKEH_RESIZE, figsize[1] * self.BOKEH_RESIZE)

        if not _BOKEH_OUTPUT_NOTEBOOK_ACTIVATED:
            bkh.output_notebook()
            _BOKEH_OUTPUT_NOTEBOOK_ACTIVATED = True

        current_plot = bkh.figure(title=title, plot_width=figsize[0], plot_height=figsize[1])
        _COLOR_CYCLE_BOKEH = itertools.cycle(COLOR_ARRAY_BOKEH)

        if xlim is not None:
            current_plot.x_range = Range1d(start=xlim[0], end=xlim[1])
        if ylim is not None:
            current_plot.y_range = Range1d(start=ylim[0], end=ylim[1])
        current_plot.title_text_font_size = value("{}pt".format(fontsize))
        current_plot.xaxis.axis_label = xlabel
        current_plot.yaxis.axis_label = ylabel
        current_plot.legend.orientation = 'top_right'

        current_plot = self._plot_bokeh(current_plot, show_legend)
        bkh.show(current_plot)
コード例 #35
0
def mzImages(filename_in_list,save_dir):
    import sys
    sys.path.append('C:\\Users\\Luca Rappez\\Desktop\\python_codebase\\')
    from pyMS.centroid_detection import gradient
    from pyIMS.hdf5.inMemoryIMS_hdf5 import inMemoryIMS_hdf5
    from pyIMS.image_measures import level_sets_measure
    import matplotlib.pyplot as plt
    import numpy as np
    #%matplotlib inline
    import bokeh as bk
    from bokeh.plotting import output_notebook
    output_notebook()
    ppm = 0.75
    if len(list)>2:
        raise ValueError('list should only have two entries')
    c_thresh=0.05
    mz_list_all=[]
    for filename_in in filename_in_list:
     # Parse data
        IMS_dataset = inMemoryIMS_hdf5(filename_in)
        hist_axis,freq_spec = IMS_dataset.generate_summary_spectrum(summary_type='freq',ppm=ppm/2)
        # Centroid detection of frequency spectrum
        mz_list,count_list,idx_list = gradient(np.asarray(hist_axis),np.asarray(freq_spec),weighted_bins=2)
        mz_list=[m for m,c in zip(mz_list,count_list) if c>c_thresh]
        mz_list_all.append(mz_list)

    im_list = [m for m in mz_list_all[0] if any([1e6*(m-mm)/m<ppm for mm in mz_list_all[1]]) ]

    """# Calcualte MoC for images of all peaks
    nlevels=30
    im_list={}
    for ii, c in enumerate(count_list):
        ion_image = IMS_dataset.get_ion_image(np.asarray([mz_list[ii],]),ppm)
        im = ion_image.xic_to_image(0)
        m,im_moc,levels,nobjs = level_sets_measure.measure_of_chaos(im,nlevels,interp='median') #just output measure value
        m=1-m
        im_list[mz_list[ii]]={'image':im,'moc':m,'freq':c}
"""
    from pySpatialMetabolomics.tools import colourmaps
    c_map = colourmaps.get_colormap('grey')#if black images: open->save->rerun
    c_pal=[[int(255*cc) for cc in c_map(c)] for c in range(0,254)]

    # Export all images
    import png as pypng
    for filename_in in filename_in_list:
     # Parse data
        IMS_dataset = inMemoryIMS_hdf5(filename_in)
        for mz in im_list:
            with open('{}/{}_{}.png'.format(save_dir,mz,filename_in),'wb') as f_out:
                im_out = IMS_dataset.get_ion_image([mz,],[ppm,]).xic_to_image(0)
                im_out = 254*im_out/np.max(im_out)
                w,h = np.shape(im_out)
                w = pypng.Writer(h, w, palette=c_pal, bitdepth=8)
                w.write(f_out,im_out)
コード例 #36
0
ファイル: plotfits_new.py プロジェクト: mariusei/scripts
    def plot_spectrum(self):
        ##fig1, ax1 = plt.subplots(1, figsize=(20,10))
        #ax1.plot(self.wls, self.data, self.wls, self.dataMEANlong, self.wls, self.dataMEANshort)
        #plt.show()

        output_notebook()
        p = figure()
        p.line(self.wls, self.data)
        p.line(self.wls, self.dataMEANlong, legend='Continuum Mean')
        p.line(self.wls, self.dataMEANshort, legend='Line mean')
        show(p)
コード例 #37
0
ファイル: scanners.py プロジェクト: thomasbkahn/svc-opt
    def _make_multiplot(self):

        self._make_datasource()


        self._make_hovertool_string()
        figs = [self._make_patch_plot(title) for title in self.plot_params['plot_titles']]

        for fig_i in figs[1:]:
            fig_i.x_range = figs[0].x_range
            fig_i.y_range = figs[0].y_range

        for i, fig in enumerate(figs):
            fig.title_text_color = 'black'
            fig.axis.axis_label_text_color = 'black'
            fig.axis.major_label_text_color = '#B3B3B3'
            fig.title_text_font_size = '18pt'
            fig.axis.axis_label_text_font_size = '12pt'
            fig.axis.major_label_text_font_size= '9pt'
            fig.axis.minor_tick_line_color = None
            fig.axis.major_tick_in = -2
            fig.axis.major_tick_out = 8
            fig.axis.major_tick_line_color = '#B3B3B3'
            fig.axis.major_tick_line_width = 2
            fig.axis.major_tick_line_cap = 'butt'
            fig.xaxis.axis_label = self.plot_params['x_label']
            fig.yaxis.axis_label = self.plot_params['y_label']
            fig.outline_line_width = 0.5
            fig.outline_line_color = 'black'
            if not self.logvals:
                fig.xaxis[0].formatter = PrintfTickFormatter(format="%0.1e")
                fig.yaxis[0].formatter = PrintfTickFormatter(format="%0.1e")
            hover = fig.select_one(HoverTool)
            hover.point_policy = "follow_mouse"
            hover.tooltips = self._hovertool_html[i]

        n_cols = self.plot_params['n_cols']
        n_figs = len(figs)
        figs = [figs[i*n_cols:(i+1)*n_cols] for i in range((n_figs//n_cols)+1)]
        if n_figs % n_cols == 0:
            figs=figs[:-1]
        fig = gridplot(figs)

        save_string = self.plot_params['save_string']

        if not save_string:
            output_notebook()
            show(fig)
        elif save_string == 'return':
            return(fig)
        elif save_string.endswith('.html'):
            output_file(save_string)
            save(fig)
コード例 #38
0
def plot_height():
    """
    Plot of height by yardage with tabs for each position.

    Calls:
    make_dfs(), rb(), wr(), qb()
    """
    dfRB, dfWR, dfQB = make_dfs()
    output_notebook()
#    output_file('40yd.html')
    tab1 = rb('heightinchestotal', 'Height (in)', 'RB: Total Yards by Height', 'Height (in)', dfRB, dfWR, dfQB)
    tab3 = qb('heightinchestotal', 'Height (in)', 'QB: Total Yards by Height', 'Height (in)', dfRB, dfWR, dfQB)
    tab2 = wr('heightinchestotal', 'Height (in)', 'WR: Total Yards by Height', 'Height (in)', dfRB, dfWR, dfQB)
    tabs = Tabs(tabs=[ tab1, tab2, tab3 ])
    show(tabs)
コード例 #39
0
def plot_40dash():
    """
    Plot of 40 yard times by yardage with tabs for each position.

    Calls:
    make_dfs(), rb(), wr(), qb()
    """
    dfRB, dfWR, dfQB = make_dfs()
    output_notebook()
#    output_file('40yd.html')
    tab1 = rb('fortyyd', '40 Yard Dash', 'RB: Total Yards by 40 Yard Dash', '40 Yard Dash', dfRB, dfWR, dfQB)
    tab2 = wr('fortyyd', '40 Yard Dash', 'WR: Total Yards by 40 Yard Dash', '40 Yard Dash', dfRB, dfWR, dfQB)
    tab3 = qb('fortyyd', '40 Yard Dash', 'QB: Total Yards by 40 Yard Dash', '40 Yard Dash', dfRB, dfWR, dfQB)
    tabs = Tabs(tabs=[ tab1, tab2, tab3 ])
    show(tabs)
コード例 #40
0
ファイル: Miscellaneous.py プロジェクト: valmick/Python
def test_bernoulli():
    values = 100
    colors = gen_n_colors(100)
    wealth=1000
    output_notebook()
    results=[]
    iteration=50
    index = 0
    for fee in np.linspace(2,200,values):
        results=bernoulli_st_petersburg_ufunc(wealth,iteration,fee)
        
        x = np.arange(len(results))
        line(x,results,line_color=colors[index])
        index = index + 1
    show()
コード例 #41
0
def plot_speedscore():
    """
    Plot of speedscore by yardage with tabs for each position.

    Calls:
    make_dfs(), rb(), wr(), qb()
    """
    dfRB, dfWR, dfQB = make_dfs()
    output_notebook()
#    output_file('40yd.html')
    tab1 = rb('speedscore', 'Speed Score', 'RB: Total Yards by Speed Score', 'Speed Score', dfRB, dfWR, dfQB)
    tab3 = qb('speedscore', 'Speed Score', 'QB: Total Yards by Speed Score', 'Speed Score', dfRB, dfWR, dfQB)
    tab2 = wr('speedscore', 'Speed Score', 'WR: Total Yards by Speed Score', 'Speed Score', dfRB, dfWR, dfQB)
    tabs = Tabs(tabs=[ tab1, tab2, tab3 ])
    show(tabs)
コード例 #42
0
ファイル: decomposition.py プロジェクト: Tong-Chen/flotilla
    def _plot_bokeh(self, metadata=None, title=''):
        metadata = metadata if metadata is not None else pd.DataFrame(
            index=self.reduced_space.index)
        # Clean alias
        import bokeh.plotting as bk
        from bokeh.plotting import ColumnDataSource, figure, show
        from bokeh.models import HoverTool

        # Plots can be displayed inline in an IPython Notebook
        bk.output_notebook(force=True)

        # Create a set of tools to use
        TOOLS = "pan,wheel_zoom,box_zoom,reset,hover"

        x = self.reduced_space[self.x_pc]
        y = self.reduced_space[self.y_pc]

        radii = np.ones(x.shape)

        colors = self.reduced_space.index.map(
            lambda x: self.label_to_color[self.groupby[x]])
        sample_ids = self.reduced_space.index

        data = dict(
            (col, metadata[col][self.reduced_space.index]) for
            col in metadata)
        tooltips = [('sample_id', '@sample_ids')]
        tooltips.extend([(k, '@{}'.format(k)) for k in data.keys()])

        data.update(dict(
            x=x,
            y=y,
            colors=colors,
            sample_ids=sample_ids
        ))

        source = ColumnDataSource(
            data=data
        )

        p = figure(title=title, tools=TOOLS)

        p.circle(x, y, radius=radii, source=source,
                 fill_color=colors, fill_alpha=0.6, line_color=None)
        hover = p.select(dict(type=HoverTool))
        hover.tooltips = tooltips

        show(p)
コード例 #43
0
def dataVisualizationUsingBokeh():
	# import modules 
	from bokeh.plotting import figure, output_notebook, show 
	  
	# output to notebook 
	output_notebook() 
	  
	# create figure 
	p = figure(plot_width = 400, plot_height = 400) 
	  
	# add a circle renderer with 
	# size, color and alpha 
	p.circle([1, 2, 3, 4, 5], [4, 7, 1, 6, 3],  
			 size = 10, color = "navy", alpha = 0.5) 
	  
	# show the results 
	show(p)  
コード例 #44
0
ファイル: __init__.py プロジェクト: tjfulle/matmodlab
def init_from_matmodlab_magic(p):
    if p == BOKEH:
        from bokeh.plotting import output_notebook
        output_notebook()
        environ.plotter = BOKEH
        i = 2
    elif p == MATPLOTLIB:
        environ.plotter = MATPLOTLIB
        i = 1

    environ.notebook = i
    environ.verbosity = 0
    try:
        from sympy import init_printing
        init_printing()
    except ImportError:
        pass
コード例 #45
0
def plot_twentyss():
    """
    Plot of 20 yard shuttle times by yardage with tabs for each position.

    Calls:
    make_dfs(), rb(), wr(), qb()
    """
    dfRB, dfWR, dfQB = make_dfs()
    dfRB = dfRB[dfRB.twentyss > 0]
    dfWR = dfWR[dfWR.twentyss > 0]
    dfQB = dfQB[dfQB.twentyss > 2] #Remove Alex Smith (incorrect time)

    output_notebook()
#    output_file('40yd.html')
    tab1 = rb('twentyss', '20 Yd Shuttle', 'RB: Total Yards by Short Shuttle', '20 Yard Short Shuttle', dfRB, dfWR, dfQB)
    tab2 = wr('twentyss', '20 Yd Shuttle', 'WR: Total Yards by Short Shuttle', '20 Yard Short Shuttle', dfRB, dfWR, dfQB)
    tab3 = qb('twentyss', '20 Yd Shuttle', 'QB: Total Yards by Short Shuttle', '20 Yard Short Shuttle', dfRB, dfWR, dfQB)
    tabs = Tabs(tabs=[ tab1, tab2, tab3 ])
    show(tabs)
コード例 #46
0
ファイル: bokeh_utils.py プロジェクト: ChristopherLu/ASRDemos
	def __init__(self,title,lines,width=900,height=300):
		
		global plots_initialized
		if not plots_initialized:
			plots_initialized=True
			output_notebook()

		self.P=figure(title=title)
		self.P.plot_width=width
		self.P.plot_height=height

		self.src=[]
		i=0
		for line in lines:
			s=ColumnDataSource(name=line)
			self.src.append(s)
			self.P.line([],[],source=s,legend=line,line_color=self.color[i])
			i+=1

		show(self.P)
コード例 #47
0
    def __init__(self, addr=None, interval=1.00):
        if addr is None:
            scheduler = default_executor().scheduler
            if isinstance(scheduler, rpc):
                addr = (scheduler.ip, scheduler.port)
            elif isinstance(scheduler, Scheduler):
                addr = ('127.0.0.1', scheduler.port)

        self.cds = ColumnDataSource({k: []
            for k in ['host', 'processing', 'stacks', 'waiting',
                      'zero', 'left', 'mid', 'right']})

        self.display_notebook = False


        left_range = Range1d(0, 1)
        self.figure = figure(height=200, width=800, y_range=left_range)
        self.figure.extra_y_ranges = {'waiting': Range1d(start=0, end=1)}
        self.figure.add_layout(LinearAxis(y_range_name='waiting',
                                          axis_label='waiting'), 'right')
        self.figure.logo = None

        proc = self.figure.quad(legend='processing', left='left', right='mid',
                              bottom='zero', top='nprocessing', source=self.cds,
                              color=(0, 0, 255, 0.5))
        wait = self.figure.quad(legend='waiting', left='mid', right='right',
                              bottom='zero', top='waiting', source=self.cds,
                              y_range_name='waiting', color=(255, 0, 0, 0.5))

        self.figure.add_tools(HoverTool(renderers=[proc, wait],
                                        tooltips=[("host", "@host"),
                                                  ("processing", "@processing"),
                                                  ("waiting", "@waiting")]))

        self.future = self.update(addr, interval)

        if is_kernel() and not curstate().notebook:
            output_notebook()
            assert curstate().notebook
コード例 #48
0
ファイル: qfp.py プロジェクト: astroChasqui/python
def plot(x, y, labels=None, **kwargs):
    TOOLS="pan,wheel_zoom,box_zoom,reset,hover"
    p = figure(tools=TOOLS, **kwargs)
    try:
        l = list(labels)
    except:
        l = list(x)
    source = ColumnDataSource(
        data=dict(
            x = x,
            y = y,
            l = l,
        )
    )
    p.scatter(x, y, size=10, source=source)
    hover = p.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([
        ("Label", "@l"),
        ("X", "@x"),
        ("Y", "@y"),
    ])
    output_notebook()
    show(p)
コード例 #49
0
def bokeh_zone_colour_map(data_source, notebook=False):
    """
    Colour each station depending on the zone
    :param data_source:
    :return:
    """
    """
    :param data_source:
    :return:
    """
    #define the colours for each zone
    if notebook:
        output_notebook()
    else:
        output_file("bokeh_zonecolourlondontuberandomsize.html")
    TOOLS="resize,hover,save"
    zonecolour_tubemap=figure(title="The London Underground", tools=TOOLS)
    zonecolour_tubemap.plot_height=800
    zonecolour_tubemap.plot_width=800
    zonecolour_tubemap.xgrid.grid_line_color = None
    zonecolour_tubemap.ygrid.grid_line_color = None
    sizes=np.random.randint(5,25,len(data_source.data["longitudes"]))
    zonecolour_tubemap.circle(data_source.data["longitudes"], data_source.data["latitudes"], sizes=10, color=data_source.data["colours"], alpha=0.6)
    show(zonecolour_tubemap)
コード例 #50
0
ファイル: config.py プロジェクト: biosustain/cameo
# Determine available solver interfaces
solvers = {}

try:
    from optlang import glpk_interface

    solvers['glpk'] = glpk_interface
except ImportError:
    pass
try:
    from optlang import cplex_interface

    solvers['cplex'] = cplex_interface
except ImportError:
    pass

# Determine if bokeh is available
try:
    import bokeh
except ImportError:
    use_bokeh = False
else:
    if in_ipnb():
        from bokeh.plotting import output_notebook
        output_notebook(hide_banner=True)
    use_bokeh = True
    bokeh_url = 'default'

# Set default parallelization view
default_view = SequentialView()
コード例 #51
0
ファイル: plotter_bokeh.py プロジェクト: jcmgray/xyzpy
def _init_bokeh_nb():
    """Cache this so it doesn't happen over and over again.
    """
    from bokeh.plotting import output_notebook
    from bokeh.resources import INLINE
    output_notebook(resources=INLINE)
コード例 #52
0
ファイル: image_autogen.py プロジェクト: LucaRappez/pyIMS
def mzImages(filename_in,save_dir):
    import sys
    sys.path.append('C:\\Users\\Luca Rappez\\Desktop\\python_codebase\\')
    from pyMS.centroid_detection import gradient
    from pyIMS.hdf5.inMemoryIMS_hdf5 import inMemoryIMS_hdf5
    from pyIMS.image_measures import level_sets_measure
    import matplotlib.pyplot as plt
    import numpy as np
    #%matplotlib inline
    import bokeh as bk
    from bokeh.plotting import output_notebook
    output_notebook()

    print 'step1'
    #filename_in =  '//psi.embl.de/alexandr/shared/Luca/20150825_CoCulture_Candida_Ecoli/20150821_ADP_LR_colony250K12_DHBsub_260x280_50um.hdf5' #using a temporary hdf5 based format
    #save_dir= '//psi.embl.de/alexandr/shared/Luca/20150825_CoCulture_Candida_Ecoli/20150821_ADP_LR_colony250K12_DHBsub_260x280_50um_figures'

    # Parse data
    IMS_dataset = inMemoryIMS_hdf5(filename_in)
    print 'In memory'
    ppm = 1.5

    # Generate mean spectrum
    #hist_axis,mean_spec =IMS_dataset.generate_summary_spectrum(summary_type='mean')
    hist_axis,freq_spec = IMS_dataset.generate_summary_spectrum(summary_type='freq',ppm=ppm/2)

    #p1 = bk.plotting.figure()
    #p1.line(hist_axis,mean_spec/np.max(mean_spec),color='red')
    #p1.line(hist_axis,freq_spec/np.max(freq_spec),color='orange')
    #bk.plotting.show(p1)
    print len(hist_axis)
    #plt.figure(figsize=(20,10))
    #plt.plot(hist_axis,freq_spec)
    #plt.show()

    # Centroid detection of frequency spectrum
    mz_list,count_list,idx_list = gradient(np.asarray(hist_axis),np.asarray(freq_spec),weighted_bins=2)

    c_thresh=0.05
    moc_thresh=0.99
    print np.sum(count_list>c_thresh)

    # Calcualte MoC for images of all peaks
    nlevels=30
    im_list={}
    for ii, c in enumerate(count_list):
        #print ii
        #print c
        if c>c_thresh:
            ion_image = IMS_dataset.get_ion_image(np.asarray([mz_list[ii],]),ppm)
            im = ion_image.xic_to_image(0)
            m,im_moc,levels,nobjs = level_sets_measure.measure_of_chaos(im,nlevels,interp='median') #just output measure value
            m=1-m
            im_list[mz_list[ii]]={'image':im,'moc':m,'freq':c}

    from pySpatialMetabolomics.tools import colourmaps
    c_map = colourmaps.get_colormap('grey')#if black images: open->save->rerun
    c_pal=[[int(255*cc) for cc in c_map(c)] for c in range(0,254)]

    # Export all images
    import png as pypng
    for mz in im_list:
        if im_list[mz]['moc']>moc_thresh:
             with open('{}/{}_{}.png'.format(save_dir,mz,im_list[mz]['moc']),'wb') as f_out:
                im_out = im_list[mz]['image']
                im_out = 254*im_out/np.max(im_out)
                w,h = np.shape(im_out)
                w = pypng.Writer(h, w, palette=c_pal, bitdepth=8)
                w.write(f_out,im_out)

    #im_out = im_list[mz]['image']
    mz=333.334188269
    ion_image = IMS_dataset.get_ion_image(np.asarray([mz,]),ppm)
    im_out=ion_image.xic_to_image(0)
    m,im_moc,levels,nobjs = level_sets_measure.measure_of_chaos(im,nlevels,interp='') #just output measure value
    print 1-m
    im_out = 254.*im_out/np.max(im_out)
    print mz
    #print im_list[mz]['moc']
    #plt.figure()
    #plt.imshow(im_moc)
    #plt.show()
コード例 #53
0
ファイル: graphs.py プロジェクト: humm/recode
    ## Disable autoscrolling

from IPython.display import display, Javascript

disable_js = """
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}
"""
display(Javascript(disable_js))



# load bokeh for jupyter
bkp.output_notebook(hide_banner=True)

#
def show(grid):
    """Display graphs, accepts a list of list of figures.

    The postures(), goals() and effects() functions display their
    graphs automatically unless the keyword argument `show` is set
    to False.
    """
    bkp.show(bkp.gridplot(grid))


def tweak_fig(fig):
    tight_layout(fig)
    three_ticks(fig)
コード例 #54
0
ファイル: mfplotting.py プロジェクト: guiwitz/PyMicrofluidics
def plot_design(design):
    output_notebook()
    sel_mult = SelectMultiple(options = [x for x in design.layers])
    interactive_plot = interactive(layer_select, m=sel_mult, design=fixed(design))
    display(interactive_plot)
コード例 #55
0
    all_scores.append(scores)


# ## Painting

# In[11]:

get_ipython().magic("matplotlib inline")


# In[12]:

from matplotlib import pyplot as plt

plt.plot(parameter_values, avg_scores, "-o")


# ## Painting with Bokeh

# In[18]:

from bokeh.plotting import figure, output_notebook, show

output_notebook()
p = figure()
p.line(parameter_values, avg_scores, line_width=2)
show(p)


# In[ ]:
コード例 #56
0
def nb_view_patches(Yr, A, C, b, f, d1, d2, image_neurons=None, thr=0.99):
    '''
    Interactive plotting utility for ipython notbook

    Parameters
    -----------
    Yr: np.ndarray
        movie
    A,C,b,f: np.ndarrays
        outputs of matrix factorization algorithm

    d1,d2: floats
        dimensions of movie (x and y)

    image_neurons: np.ndarray
        image to be overlaid to neurons (for instance the average)

    thr: double
        threshold regulating the extent of the displayed patches


    '''
    colormap = cm.get_cmap("jet")  # choose any matplotlib colormap here
    grayp = [mpl.colors.rgb2hex(m) for m in colormap(np.arange(colormap.N))]
    nr, T = C.shape
    nA2 = np.sum(np.array(A)**2, axis=0)
    b = np.squeeze(b)
    f = np.squeeze(f)
    #Y_r = np.array(spdiags(1/nA2,0,nr,nr)*(A.T*np.matrix(Yr-b[:,np.newaxis]*f[np.newaxis] - A.dot(C))) + C)
    Y_r = np.array(spdiags(1 / nA2, 0, nr, nr) * (A.T * np.matrix(Yr) - (A.T *
                                                                         np.matrix(b[:, np.newaxis])) * np.matrix(f[np.newaxis]) - (A.T.dot(A)) * np.matrix(C)) + C)

    bpl.output_notebook()
    x = np.arange(T)
    z = np.squeeze(np.array(Y_r[:, :].T)) / 100
    k = np.reshape(np.array(A), (d1, d2, A.shape[1]), order='F')
    if image_neurons is None:
        image_neurons = np.nanmean(k, axis=2)

    fig = plt.figure()
    coors = plot_contours(coo_matrix(A), image_neurons, thr=thr)
    plt.close()
#    cc=coors[0]['coordinates'];
    cc1 = [cor['coordinates'][:, 0] for cor in coors]
    cc2 = [cor['coordinates'][:, 1] for cor in coors]
    c1 = cc1[0]
    c2 = cc2[0]
    npoints = range(len(c1))

    source = ColumnDataSource(data=dict(x=x, y=z[:, 0], z=z))
    source2 = ColumnDataSource(data=dict(x=npoints, c1=c1, c2=c2, cc1=cc1, cc2=cc2))

    plot = bpl.figure(plot_width=600, plot_height=300)
    plot.line('x', 'y', source=source, line_width=1, line_alpha=0.6)

    callback = CustomJS(args=dict(source=source, source2=source2), code="""
            var data = source.get('data');
            var f = cb_obj.get('value')-1
            x = data['x']
            y = data['y']
            z = data['z']

            for (i = 0; i < x.length; i++) {
                y[i] = z[i][f]
            }

            var data2 = source2.get('data');
            c1 = data2['c1'];
            c2 = data2['c2'];
            cc1 = data2['cc1'];
            cc2 = data2['cc2'];

            for (i = 0; i < c1.length; i++) {
                   c1[i] = cc1[f][i]
                   c2[i] = cc2[f][i]
            }
            source2.trigger('change');
            source.trigger('change');

        """)

    slider = bokeh.models.Slider(start=1, end=Y_r.shape[
                                 0], value=1, step=1, title="Neuron Number", callback=callback)
    xr = Range1d(start=0, end=image_neurons.shape[1])
    yr = Range1d(start=image_neurons.shape[0], end=0)
    plot1 = bpl.figure(x_range=xr, y_range=yr, plot_width=300, plot_height=300)
    plot1.image(image=[image_neurons[::-1, :]], x=0,
                y=image_neurons.shape[0], dw=d2, dh=d1, palette=grayp)
    plot1.patch('c1', 'c2', alpha=0.6, color='purple', line_width=2, source=source2)

    layout = vform(slider, hplot(plot1, plot))

    bpl.show(layout)

    return Y_r
コード例 #57
0
 def show_notebook(self, fig):
     bkp.output_notebook()
     bkp.show(fig)
コード例 #58
0
ファイル: bokeh_magic.py プロジェクト: TIC-External/bokeh
 def notebook_output(self):
     """Wrapper to execute the open notebook function just once to avoid 
     a javascript annoying bug when it is called multiple times."""
     output_notebook()
     self.has_run = True
コード例 #59
0
ファイル: quickstart.py プロジェクト: gree2/hobby
#! coding: utf-8
"""getting start with bokeh"""

from bokeh.plotting import figure, output_file, output_notebook, show

x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

# output_file('lines.html', title='line plot example')
output_notebook('lines.html')

p = figure(title='simple line example', x_axis_label='x', y_axis_label='y')

p.line(x, y, legend="Temp.", line_width=2)

show(p)

from ipywidgets import interact
import numpy as np

from bokeh.io import push_notebook
from bokeh.plotting import figure, show, output_notebook

x = np.linspace(0, 2 * np.pi, 2000)
y = np.sin(x)

output_notebook()

p = figure(title='simple line example', plot_height=300, plot_width=600, y_range=(-5, 5))
r = p.line(x, y, color='#2222aa', line_width=3)