Shade Positive and Negative Regions#

It can be useful to call out positive or negative areas within a chart, especially for growth rate visualizations. This is achieved using the shade_y instance and specifying the appropriate start, end, and color.

  • Use 2 regions to define the positive and negative areas and use the color to indicate if it is positive (green) or negative (red)

  • It can be beneficial to fix the axis_min and axis_max as well so that the start and end values of the region are easier to define.



import pandas as pd

from visualization_toolkit.helpers.plotly import chart, axis, series, shade_y


fig = chart(
    pdf,
    x_axis=axis(column_name="fiscal_qy", label="Fiscal Quarter"),
    chart_series=[
        series(
            column_name="yy",
            label="Y/Y Growth Rate",
            color="black",
            location="y1",
            shape="dash",
        ),
    ],
    y1_axis=axis(label="Growth Rate", axis_type="percent", axis_min=-0.2, axis_max=0.2),
    shaded_regions=[
        shade_y(
            start=-0.2,
            end=0,
            color="red",
        ),
        shade_y(
            start=0,
            end=0.2,
            color="green",
        ),
    ],
)

fig

Total running time of the script: (0 minutes 0.023 seconds)

Gallery generated by Sphinx-Gallery