當前位置: 首頁>>代碼示例>>Python>>正文


Python models.ColumnDataSource方法代碼示例

本文整理匯總了Python中bokeh.models.ColumnDataSource方法的典型用法代碼示例。如果您正苦於以下問題:Python models.ColumnDataSource方法的具體用法?Python models.ColumnDataSource怎麽用?Python models.ColumnDataSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bokeh.models的用法示例。


在下文中一共展示了models.ColumnDataSource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def create(clz):
        """One-time creation of app's objects.

        This function is called once, and is responsible for
        creating all objects (plots, datasources, etc)
        """
        self = clz()
        n_vals = 1000
        self.source = ColumnDataSource(
            data=dict(
                top=[],
                bottom=0,
                left=[],
                right=[],
                x= np.arange(n_vals),
                values= np.random.randn(n_vals)
                ))

        # Generate a figure container
        self.stock_plot = clz.create_stock(self.source)
        self.update_data()
        self.children.append(self.stock_plot) 
開發者ID:mvaz,項目名稱:osqf2015,代碼行數:24,代碼來源:stock.py

示例2: make_plot

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def make_plot(self, dataframe):
        self.source = ColumnDataSource(data=dataframe)
        self.plot = figure(
            x_axis_type="datetime", plot_width=600, plot_height=300,
            tools='', toolbar_location=None)
        self.plot.quad(
            top='max_temp', bottom='min_temp', left='left', right='right',
            color=Blues4[2], source=self.source, legend='Magnitude')
        line = self.plot.line(
            x='date', y='avg_temp', line_width=3, color=Blues4[1],
            source=self.source, legend='Average')
        hover_tool = HoverTool(tooltips=[
            ('Value', '$y'),
            ('Date', '@date_readable'),
        ], renderers=[line])
        self.plot.tools.append(hover_tool)

        self.plot.xaxis.axis_label = None
        self.plot.yaxis.axis_label = None
        self.plot.axis.axis_label_text_font_style = 'bold'
        self.plot.x_range = DataRange1d(range_padding=0.0)
        self.plot.grid.grid_line_alpha = 0.3

        self.title = Paragraph(text=TITLE)
        return column(self.title, self.plot) 
開發者ID:GoogleCloudPlatform,項目名稱:bigquery-bokeh-dashboard,代碼行數:27,代碼來源:temperature.py

示例3: make_plot

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def make_plot(self, dataframe):
        self.source = ColumnDataSource(data=dataframe)
        palette = all_palettes['Set2'][6]
        hover_tool = HoverTool(tooltips=[
            ("Value", "$y"),
            ("Year", "@year"),
        ])
        self.plot = figure(
            plot_width=600, plot_height=300, tools=[hover_tool],
            toolbar_location=None)
        columns = {
            'pm10': 'PM10 Mass (µg/m³)',
            'pm25_frm': 'PM2.5 FRM (µg/m³)',
            'pm25_nonfrm': 'PM2.5 non FRM (µg/m³)',
            'lead': 'Lead (¹/₁₀₀ µg/m³)',
        }
        for i, (code, label) in enumerate(columns.items()):
            self.plot.line(
                x='year', y=code, source=self.source, line_width=3,
                line_alpha=0.6, line_color=palette[i], legend=label)

        self.title = Paragraph(text=TITLE)
        return column(self.title, self.plot)
# [END make_plot] 
開發者ID:GoogleCloudPlatform,項目名稱:bigquery-bokeh-dashboard,代碼行數:26,代碼來源:air.py

示例4: make_plot

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def make_plot(self, dataframe):
        self.source = ColumnDataSource(data=dataframe)
        self.plot = figure(
            x_axis_type="datetime", plot_width=400, plot_height=300,
            tools='', toolbar_location=None)

        vbar = self.plot.vbar(
            x='date', top='prcp', width=1, color='#fdae61', source=self.source)
        hover_tool = HoverTool(tooltips=[
            ('Value', '$y'),
            ('Date', '@date_readable'),
        ], renderers=[vbar])
        self.plot.tools.append(hover_tool)

        self.plot.xaxis.axis_label = None
        self.plot.yaxis.axis_label = None
        self.plot.axis.axis_label_text_font_style = 'bold'
        self.plot.x_range = DataRange1d(range_padding=0.0)
        self.plot.grid.grid_line_alpha = 0.3

        self.title = Paragraph(text=TITLE)
        return column(self.title, self.plot) 
開發者ID:GoogleCloudPlatform,項目名稱:bigquery-bokeh-dashboard,代碼行數:24,代碼來源:precipitation.py

示例5: app

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def app(doc):

    x,y = SineWave()
    source = ColumnDataSource(data=dict(x=x, y=y))

    import numpy as np # see TODO below about ranges
    plot = figure(plot_height=400, plot_width=400,
                  tools="crosshair,pan,reset,save,wheel_zoom",
                  x_range=[0, 4*np.pi], y_range=[-2.5, 2.5])
    plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

    def update_sinewave(sw,**kw):
        x,y = sw()
        source.data = dict(x=x, y=y)
        # TODO couldn't figure out how to update ranges
        #plot.x_range.start,plot.x_range.end=pobj.x_range
        #plot.y_range.start,plot.y_range.end=pobj.y_range
    
    parambokeh.Widgets(SineWave, mode='server', doc=doc, callback=update_sinewave)
    doc.add_root(row(plot, width=800)) 
開發者ID:ioam,項目名稱:parambokeh,代碼行數:22,代碼來源:bk_sliders.py

示例6: master_app

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def master_app(doc, database_name_to_path, session_data):
    """Create the page with the master dashboard.

    Args:
        doc (bokeh.Document):
            document where the overview over the optimizations will be displayed
            by their current stage.
        database_name_to_path (dict):
            mapping from the short, unique names to the full paths to the databases.
        session_data (dict):
            infos to be passed between and within apps.
            Keys of the monitoring apps' entries are:
            - last_retrieved (int): last iteration currently in the ColumnDataSource
            - database_path

    """
    sec_to_elements = _create_section_to_elements(
        doc=doc, database_name_to_path=database_name_to_path
    )
    tabs = _setup_tabs(sec_to_elements=sec_to_elements)
    doc.add_root(tabs) 
開發者ID:OpenSourceEconomics,項目名稱:estimagic,代碼行數:23,代碼來源:master_app.py

示例7: _map_dabase_name_to_bokeh_row_elements

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def _map_dabase_name_to_bokeh_row_elements(doc, database_name_to_path):
    """Inner part of the sec_to_elements dictionary.

    For each entry that belongs to the section create a clickable link to that
    optimization's monitoring page.

    Args:
        doc (bokeh Document)
        database_name_to_path (dict): mapping from the short, unique names to the full
            paths to the databases.

    """
    name_to_row = {}
    for database_name in database_name_to_path:
        name_to_row[database_name] = [create_dashboard_link(database_name)]
    return ColumnDataSource(name_to_row) 
開發者ID:OpenSourceEconomics,項目名稱:estimagic,代碼行數:18,代碼來源:master_app.py

示例8: _create_bokeh_data_sources

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def _create_bokeh_data_sources(database, tables):
    """Load the first entry from the database to initialize the ColumnDataSources.

    Args:
        database (sqlalchemy.MetaData)
        tables (list): list of table names to load and convert to ColumnDataSources

    Returns:
        all_cds (list): list of ColumnDataSources

    """
    data_dict, _ = read_new_iterations(
        database=database,
        tables=tables,
        last_retrieved=0,
        limit=1,
        return_type="bokeh",
    )

    all_cds = []
    for tab, data in data_dict.items():
        cds = ColumnDataSource(data=data, name=f"{tab}_cds")
        all_cds.append(cds)
    return all_cds 
開發者ID:OpenSourceEconomics,項目名稱:estimagic,代碼行數:26,代碼來源:monitoring_app.py

示例9: run

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def run(self):
        print("In thread.run")
        self.p = figure(plot_height=500, tools=TOOLS, y_axis_location='left', title=self.title)
        self.p.x_range.follow = "end"
        self.p.xaxis.axis_label = "Timestamp"
        self.p.x_range.follow_interval = 100
        self.p.x_range.range_padding = 0 
        self.p.line(x="timestamp", y="value", color="blue", source=self.source)
        self.p.circle(x="timestamp", y="value", color="red", source=self.source)

        self.session = push_session(curdoc())
        curdoc().add_periodic_callback(self.update, 100) #period in ms

        self.session.show(column(self.p)) 
        curdoc().title = 'Sensor' 
        self.session.loop_until_closed()

    # def register(self, d, sourceq):
    #     source = ColumnDataSource(dict(d))
    #     self.p.line(x=d[0], y=d[1], color="orange", source=source)
    #     curdoc().add_periodic_callback(self.update, 100) #period in ms 
開發者ID:mpi-sws-rse,項目名稱:thingflow-python,代碼行數:23,代碼來源:bokeh.py

示例10: modify_doc

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def modify_doc(doc):
    df = sea_surface_temperature.copy()
    source = ColumnDataSource(data=df)

    plot = figure(x_axis_type='datetime', y_range=(0, 25), y_axis_label='Temperature (Celsius)',
                  title="Sea Surface Temperature at 43.18, -70.43")
    plot.line('time', 'temperature', source=source)

    def callback(attr, old, new):
        if new == 0:
            data = df
        else:
            data = df.rolling('{0}D'.format(new)).mean()
        source.data = ColumnDataSource(data=data).data

    slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days")
    slider.on_change('value', callback)

    doc.add_root(column(slider, plot))

    # doc.theme = Theme(filename="theme.yaml") 
開發者ID:pythonstock,項目名稱:stock,代碼行數:23,代碼來源:tornado_bokeh_embed.py

示例11: test_bokehplot

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def test_bokehplot():
    fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
    years = ['2015', '2016', '2017']

    data = {'fruits': fruits,
            '2015': [2, 1, 4, 3, 2, 4],
            '2016': [5, 3, 3, 2, 4, 6],
            '2017': [3, 2, 4, 4, 5, 3]}

    x = [(fruit, year) for fruit in fruits for year in years]
    counts = sum(zip(data['2015'], data['2016'], data['2017']), ())  # like an hstack

    source = ColumnDataSource(data=dict(x=x, counts=counts))

    fig = figure(x_range=FactorRange(*x), plot_height=350, title="Fruit Counts by Year",
                 toolbar_location=None, tools="")
    fig.vbar(x='x', top='counts', width=0.9, source=source)
    return BokehPlotBlock(fig) 
開發者ID:man-group,項目名稱:PyBloqs,代碼行數:20,代碼來源:test_image.py

示例12: get_analyzers_tables

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def get_analyzers_tables(self, analyzer: bt.analyzers.Analyzer, table_width) -> (Paragraph, List[DataTable]):
        """Return a header for this analyzer and one *or more* data tables."""
        if hasattr(analyzer, 'get_analysis_table'):
            title, table_columns_list = analyzer.get_analysis_table()
        else:
            # Analyzer does not provide a table function. Use our generic one
            title, table_columns_list = TableGenerator._get_analysis_table_generic(analyzer)

        param_str = get_params_str(analyzer.params)
        if len(param_str) > 0:
            title += f' ({param_str})'

        elems: List[DataTable] = []
        for table_columns in table_columns_list:
            cds = ColumnDataSource()
            columns = []
            for i, c in enumerate(table_columns):
                col_name = f'col{i}'
                cds.add(c[2:], col_name)
                columns.append(TableColumn(field=col_name, title=c[0], formatter=self._get_formatter(c[1])))
            column_height = len(table_columns[0]) * 25
            elems.append(DataTable(source=cds, columns=columns, index_position=None, width=table_width, height=column_height))
        return Paragraph(text=title, style={'font-size': 'large'}), elems 
開發者ID:verybadsoldier,項目名稱:backtrader_plotting,代碼行數:25,代碼來源:datatable.py

示例13: __init__

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def __init__(self, strategy: bt.Strategy, cds: ColumnDataSource, hoverc: HoverContainer, start, end, scheme, master, plotorder, is_multidata):
        self._strategy = strategy
        self._cds: ColumnDataSource = cds
        self._scheme = scheme
        self._start = start
        self._end = end
        self.figure: figure = None
        self._hover_line_set = False
        self._hover: Optional[HoverTool] = None
        self._hoverc = hoverc
        self._coloridx = collections.defaultdict(lambda: -1)
        self.master = master
        self.plottab = None
        self.plotorder = plotorder
        self.datas = []  # list of all datas that have been plotted to this figure
        self._is_multidata = is_multidata
        self._tradingdomain = None
        self._init_figure() 
開發者ID:verybadsoldier,項目名稱:backtrader_plotting,代碼行數:20,代碼來源:figureenvelope.py

示例14: update_source

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def update_source(self):
        df = pd.read_csv(StringIO(self.get_relevant_data()), delimiter='\t', header=None, names=['url', 'timestamp'])
        df['domain'] = df['url'].apply(self.extract_tld)
        df1 = df.groupby(['domain']).size()

        df = pd.read_csv(StringIO(self.get_crawled_data()), delimiter='\t', header=None, names=['url', 'timestamp'])
        df['domain'] = df['url'].apply(self.extract_tld)
        df2 = df.groupby(['domain']).size()

        df = pd.concat((df1, df2), axis=1)
        df.columns = ['relevant', 'crawled']

        df = df.sort(self.sort, ascending=False).head(25).fillna(value=0)

        for col in df.columns:
            df['%s_half' % col] = df[col] / 2

        df.reset_index(inplace=True)

        df.rename(columns={'index':'domain'}, inplace=True)

        source = into(ColumnDataSource, df)
        return source 
開發者ID:nasa-jpl-memex,項目名稱:memex-explorer,代碼行數:25,代碼來源:domain.py

示例15: update_source

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import ColumnDataSource [as 別名]
def update_source(self):
        proc = subprocess.Popen(shlex.split("tail -n 800 %s" % self.harvest_data),
                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        stdout, stderr = proc.communicate()

        if stderr or not stdout:
            raise ValueError("harvestinfo.csv is empty")

        # Converts stdout to StringIO to allow pandas to read it as a file

        df = pd.read_csv(StringIO(stdout), delimiter='\t',
                         names=['relevant_pages', 'downloaded_pages', 'timestamp'])
        df['harvest_rate'] = df['relevant_pages'] / df['downloaded_pages']
        df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')

        source = into(ColumnDataSource, df)
        return source 
開發者ID:nasa-jpl-memex,項目名稱:memex-explorer,代碼行數:20,代碼來源:harvest.py


注:本文中的bokeh.models.ColumnDataSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。