Python bokeh.palettes.viridis() Examples

The following are 5 code examples of bokeh.palettes.viridis(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bokeh.palettes , or try the search function .
Example #1
Source File: process_tree.py    From msticpy with MIT License 5 votes vote down vote up
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 
Example #2
Source File: timeline.py    From msticpy with MIT License 5 votes vote down vote up
def _get_color_palette(series_count):
    palette_size = min(256, series_count + int(series_count / 5))
    return viridis(palette_size), palette_size 
Example #3
Source File: bokeh_qc_graphs.py    From rvt_model_services with MIT License 4 votes vote down vote up
def graph(_csv, _project_code, graph_topics):
    figures = []
    graph_x_range = None
    for topic in graph_topics.keys():
        # data source
        csv_topic = _csv.copy().filter(regex=topic)
        csv_topic["timeStamp"] = _csv.timeStamp.copy()
        csv_topic.set_index('timeStamp', inplace=True)
        csv_topic.index = pd.to_datetime(csv_topic.index)
        csv_topic.sort_index(inplace=True)
        df_columns_count = csv_topic.shape[1]
        df_rows_count = csv_topic.shape[0]

        colors = viridis(df_columns_count)

        topic_title = f"{_project_code} - RVT - {graph_topics[topic]}"

        # print(topic_title)
        # print(csv_topic.head())

        line_opt = dict(line_width=3, alpha=0.8)
        hover = HoverTool(tooltips=[("name", "@name"),
                                    ("time", "@time"),
                                    ("count", "@count"),
                                    ]
                          )
        tools_opt = [hover, "save", "pan", "wheel_zoom", "reset"]
        graph_opt = dict(width=900, x_axis_type="datetime",
                         toolbar_location="left", tools=tools_opt, toolbar_sticky=False,
                         background_fill_alpha=0, border_fill_alpha=0)

        if graph_x_range:
            topic_figure = figure(title=topic_title, x_range=graph_x_range, **graph_opt)
        else:
            topic_figure = figure(title=topic_title, **graph_opt)
            graph_x_range = topic_figure.x_range

        # glyphs
        # print(len(cds.column_names))
        for i, col_name in enumerate(csv_topic.columns):
            if topic in col_name:
                # print(col_name)
                csv_topic["color"] = colors[i]
                name_list = [col_name[2:] for i in range(df_rows_count)]

                cds = ColumnDataSource(data=dict(x=csv_topic.index.values,
                                                 y=csv_topic[col_name].values,
                                                 name=name_list,
                                                 count=csv_topic[col_name].values,
                                                 time=csv_topic.index.strftime("%Y-%m-%d %H:%M:%S"),
                                                 )
                                       )

                topic_figure.line("x", "y",
                                  color=colors[i], name="name", source=cds, legend=col_name[2:],
                                  **line_opt
                                  )

        figures.append(style_plot(topic_figure))

    return figures 
Example #4
Source File: bokeh_qc_graphs.py    From rvt_model_services with MIT License 4 votes vote down vote up
def graph(_csv, _project_code, graph_topics):
    figures = []
    graph_x_range = None
    for topic in graph_topics.keys():
        # data source
        csv_topic = _csv.copy().filter(regex=topic)
        csv_topic["timeStamp"] = _csv.timeStamp.copy()
        csv_topic.set_index('timeStamp', inplace=True)
        csv_topic.index = pd.to_datetime(csv_topic.index)
        csv_topic.sort_index(inplace=True)
        df_columns_count = csv_topic.shape[1]
        df_rows_count = csv_topic.shape[0]

        colors = viridis(df_columns_count)

        topic_title = f"{_project_code} - RVT - {graph_topics[topic]}"

        # print(topic_title)
        # print(csv_topic.head())

        line_opt = dict(line_width=3, alpha=0.8)
        hover = HoverTool(tooltips=[("name", "@name"),
                                    ("time", "@time"),
                                    ("count", "@count"),
                                    ]
                          )
        tools_opt = [hover, "save", "pan", "wheel_zoom", "reset"]
        graph_opt = dict(width=900, x_axis_type="datetime",
                         toolbar_location="left", tools=tools_opt, toolbar_sticky=False,
                         background_fill_alpha=0, border_fill_alpha=0)

        if graph_x_range:
            topic_figure = figure(title=topic_title, x_range=graph_x_range, **graph_opt)
        else:
            topic_figure = figure(title=topic_title, **graph_opt)
            graph_x_range = topic_figure.x_range

        # glyphs
        # print(len(cds.column_names))
        for i, col_name in enumerate(csv_topic.columns):
            if topic in col_name:
                # print(col_name)
                csv_topic["color"] = colors[i]
                name_list = [col_name[2:] for i in range(df_rows_count)]

                cds = ColumnDataSource(data=dict(x=csv_topic.index.values,
                                                 y=csv_topic[col_name].values,
                                                 name=name_list,
                                                 count=csv_topic[col_name].values,
                                                 time=csv_topic.index.strftime("%Y-%m-%d %H:%M:%S"),
                                                 )
                                       )

                topic_figure.line("x", "y",
                                  color=colors[i], name="name", source=cds, legend=col_name[2:],
                                  **line_opt
                                  )

        figures.append(style_plot(topic_figure))

    return figures 
Example #5
Source File: bokeh_jobs_viz.py    From rvt_model_services with MIT License 4 votes vote down vote up
def update_graph(jobs_db, graph_path):
    rows = []
    for job in jobs_db.all():
        rows.append([job.get("<project_code>"), job.get("<command>"), job.get(">start_time"), job.get("timeout")])

    df = pd.DataFrame(rows, columns=["project", "command", "start", "timeout"])
    df = df.sort_values(by="project", ascending=False)
    df["start"] = pd.to_datetime(df["start"], format="%H:%M:%S")
    df["start_txt"] = df.start.astype("str").str.extract(r"(\d+:\d+)", expand=True) + " h"
    df["timeout_txt"] = df['timeout'].copy().astype('str') + " seconds"
    df["timeout"] = df['timeout'].astype('timedelta64[s]')
    df["end"] = pd.to_datetime(df["start"], format="%H:%M:%S") + df["timeout"]

    colors = viridis(len(df["project"]))
    output_file(graph_path, title="rvt_model_services_jobs", mode="inline")

    cds = ColumnDataSource(data=dict(start=df["start"].values,
                                     end=df["end"].values,
                                     name=df["project"],
                                     timeout=df["timeout_txt"],
                                     start_txt=df["start_txt"],
                                     command=df["command"],
                                     color=colors,
                                     )
                           )

    hover = HoverTool(tooltips=[("project", "@name"),
                                ("command", "@command"),
                                ("start time:", "@start_txt"),
                                ("timeout:", "@timeout"),
                                ])

    tools_opt = [hover, "save", "pan", "wheel_zoom", "box_zoom", "reset"]
    graph_opt = dict(width=900, x_axis_type="datetime",
                     tools=tools_opt,
                     toolbar_location="right",
                     background_fill_alpha=0, border_fill_alpha=0)
    jobs_viz = figure(title="rvt_model_service_jobs",
                      y_range=list(df["project"].unique()),
                      **graph_opt)
    jobs_viz.hbar(source=cds,
                  y="name",
                  left="start",
                  right="end",
                  height=1,
                  color="color",
                  )

    style_plot(jobs_viz)
    save(jobs_viz)