def style_color_palette_diverging()

in chartify/examples.py [0:0]


def style_color_palette_diverging():
    """
    Color palette sequential
    """
    import numpy as np
    import pandas as pd
    import chartify

    data = pd.DataFrame({"time": pd.date_range("2015-01-01", "2018-01-01")})
    n_days = len(data)
    data["Very Unlikely"] = np.array(list(range(n_days))) + np.random.normal(0, 10, size=n_days)
    data["Unlikely"] = np.array(list(range(n_days))) + np.random.normal(0, 10, size=n_days) + 200
    data["Neutral"] = np.array(list(range(n_days))) + np.random.normal(0, 10, size=n_days) + 500
    data["Likely"] = np.array(list(range(n_days))) + np.random.normal(0, 10, size=n_days) + 700
    data["Very Likely"] = np.array(list(range(n_days))) + np.random.normal(0, 10, size=n_days) + 800
    data = pd.melt(
        data,
        id_vars=["time"],
        value_vars=data.columns[1:],
        value_name="y",
        var_name="grouping",
    )

    # Plot the data

    ch = chartify.Chart(blank_labels=True, x_axis_type="datetime")
    ch.style.set_color_palette(palette_type="diverging")
    color_order = ["Very Unlikely", "Unlikely", "Neutral", "Likely", "Very Likely"]
    ch.plot.line(
        data_frame=data.sort_values("time"),
        x_column="time",
        y_column="y",
        color_column="grouping",
        color_order=color_order,
    )  # Your data must be sorted
    ch.set_title("Diverging color palette type")
    ch.set_subtitle("Palette type for diverging ordered dimensions")
    ch.show(_OUTPUT_FORMAT)