Note
Go to the end to download the full example code.
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
colorto indicate if it is positive (green) or negative (red)It can be beneficial to fix the
axis_minandaxis_maxas well so that thestartandendvalues 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)