当前位置: 首页>>代码示例>>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;未经允许,请勿转载。