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


Python transform.factor_cmap方法代碼示例

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


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

示例1: _create_fill_map

# 需要導入模塊: from bokeh import transform [as 別名]
# 或者: from bokeh.transform import factor_cmap [as 別名]
def _create_fill_map(
    source: ColumnDataSource, source_column: str = None
) -> Tuple[Union[factor_cmap, linear_cmap], Optional[ColorBar]]:
    """Create factor map or linear map based on `source_column`."""
    fill_map = "navy"
    color_bar = None
    if source_column is None or source_column not in source.data:
        return fill_map, color_bar

    col_kind = source.data[source_column].dtype.kind
    if col_kind in ["b", "O"]:
        s_values = set(source.data[source_column])
        if np.nan in s_values:
            s_values.remove(np.nan)
        values = list(s_values)
        fill_map = factor_cmap(
            source_column, palette=viridis(max(3, len(values))), factors=values
        )
    elif col_kind in ["i", "u", "f", "M"]:
        values = [val for val in source.data[source_column] if not np.isnan(val)]
        fill_map = linear_cmap(
            field_name=source_column,
            palette=viridis(256),
            low=np.min(values),
            high=np.max(values),
        )
        color_bar = ColorBar(
            color_mapper=fill_map["transform"], width=8, location=(0, 0)  # type: ignore
        )
    return fill_map, color_bar


# pylint: disable=too-many-arguments 
開發者ID:microsoft,項目名稱:msticpy,代碼行數:35,代碼來源:process_tree.py

示例2: step_viewer

# 需要導入模塊: from bokeh import transform [as 別名]
# 或者: from bokeh.transform import factor_cmap [as 別名]
def step_viewer(grad_data):
    mice = sorted(grad_data['subject'].unique())
    palette = [cc.rainbow[i] for i in range(len(grad_data['pilot'].unique()))]

    current_step = grad_data.groupby('subject').last().reset_index()
    current_step = current_step[['subject', 'step_n', 'pilot']]

    pilots = current_step['pilot'].unique()
    pilot_colors = {p:palette[i] for i,p in enumerate(pilots) }
    pilot_colors = [pilot_colors[p] for p in current_step['pilot']]
    current_step['colors'] = pilot_colors




    p = figure(x_range=current_step['subject'].unique(),title='Subject Steps',
               plot_height=600,
               plot_width=1000)
    p.xaxis.major_label_orientation = np.pi / 2
    bars = p.vbar(x='subject', top='step_n', width=0.9,
           fill_color=factor_cmap('pilot', palette=Spectral10, factors=pilots),
           legend='pilot',
           source=ColumnDataSource(current_step))
    p.legend.location = 'top_center'
    p.legend.orientation = 'horizontal'
    #p.add_layout(legend,'below')

    show(p) 
開發者ID:wehr-lab,項目名稱:autopilot,代碼行數:30,代碼來源:trial_viewer.py

示例3: refresh_output

# 需要導入模塊: from bokeh import transform [as 別名]
# 或者: from bokeh.transform import factor_cmap [as 別名]
def refresh_output():
    # get new data
    df = get_data(expt_select.value)
    freqs = df.frequency.unique()
    cmap = factor_cmap('frequency', palette=bokeh.palettes.Category10[10], factors=freqs)

    # update figure itself
    p.y_range.factors = list(df.variable.unique())
    (p.x_range.start, p.x_range.end) = (df.iloc[0].time_start, df.iloc[-1].time_end)
    p.title.text = expt_select.value

    # update data source for plot
    hb.data_source.data = hb.data_source.from_df(df)
    # update colourmap if necessary
    hb.glyph.fill_color = cmap 
開發者ID:COSIMA,項目名稱:cosima-cookbook,代碼行數:17,代碼來源:diag-vis.py

示例4: report_html_groupby

# 需要導入模塊: from bokeh import transform [as 別名]
# 或者: from bokeh.transform import factor_cmap [as 別名]
def report_html_groupby(logger, iteration=0):
    # type: (Logger, int) -> ()
    """
    reporting bokeh groupby (html) to debug samples section
    :param logger: The task.logger to use for sending the plots
    :param iteration: The iteration number of the current reports
    """
    output_file("bar_pandas_groupby_nested.html")
    bokeh_df.cyl = bokeh_df.cyl.astype(str)
    bokeh_df.yr = bokeh_df.yr.astype(str)
    group = bokeh_df.groupby(by=["cyl", "mfr"])
    index_cmap = factor_cmap(
        "cyl_mfr", palette=Spectral5, factors=sorted(bokeh_df.cyl.unique()), end=1
    )
    p = figure(
        plot_width=800,
        plot_height=300,
        title="Mean MPG by # Cylinders and Manufacturer",
        x_range=group,
        toolbar_location=None,
        tooltips=[("MPG", "@mpg_mean"), ("Cyl, Mfr", "@cyl_mfr")],
    )
    p.vbar(
        x="cyl_mfr",
        top="mpg_mean",
        width=1,
        source=group,
        line_color="white",
        fill_color=index_cmap,
    )
    p.y_range.start = 0
    p.x_range.range_padding = 0.05
    p.xgrid.grid_line_color = None
    p.xaxis.axis_label = "Manufacturer grouped by # Cylinders"
    p.xaxis.major_label_orientation = 1.2
    p.outline_line_color = None
    save(p)
    logger.report_media(
        "html",
        "pandas_groupby_nested_html",
        iteration=iteration,
        local_path="bar_pandas_groupby_nested.html",
    ) 
開發者ID:allegroai,項目名稱:trains,代碼行數:45,代碼來源:html_reporting.py


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