Hi plotly community,
I have created the following density plot:
using the following code:
import numpy as np
import plotly.figure_factory as ff
data = np.random.normal(0, 1, 1000)
name = "Example"
fig = ff.create_distplot([data], [name], show_hist=False, show_rug=False)
fig = fig.add_vline(
x=np.quantile(data, q=0.5),
line_width=3,
line_dash="dash",
line_color="black",
annotation_text=f"Median: {round(np.quantile(data, q=0.5))}",
annotation_position="top right",
annotation_font_size=12,
annotation_font_color="black",
)
fig = fig.add_vline(
x=np.quantile(data, q=0.05),
line_width=3,
line_dash="dash",
line_color="red",
annotation_text=f"5% Quantil: {round(np.quantile(data, q=.05))}",
annotation_position="bottom right",
annotation_font_size=12,
annotation_font_color="red",
)
fig = fig.add_vline(
x=np.quantile(data, q=0.95),
line_width=3,
line_dash="dash",
line_color="green",
annotation_text=f"95% Quantil: {round(np.quantile(data, q=.95))}",
annotation_position="bottom right",
annotation_font_size=12,
annotation_font_color="green",
)
fig.update_layout(plot_bgcolor="white")
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgrey')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgrey')
fig.update_layout(showlegend=False)
fig.update_layout(title=name)
fig
Now I would like to fill the area under the density curve and left from the red dotted line with red color and the area under the density curve right to the green dotted line with green color. But somehow I am totally lost doing it. Does anybody know how to fill those areas with color?
Thanks a lot!
Best,
chiquadrat