Hello everyone,
I am working on some histogram figures using plotly express and cannot find a smart way of custom coloring some of the bars in my plots.
My data-frame consists of 3 columns MONTH, VALUE and YEAR, which are later used for grouping data on my histogram.
MONTH YEAR VALUE
2021-01-31 January 2021 108222.870075
2021-02-28 February 2021 83786.794785
2021-03-31 March 2021 88548.563611
2021-04-30 April 2021 85295.114970
2021-05-31 May 2021 89774.342922
2021-06-30 June 2021 86139.596102
2021-07-31 July 2021 90461.141199
2021-08-31 August 2021 90309.096285
2021-09-30 September 2021 88426.021444
2021-10-31 October 2021 90145.682254
2021-11-30 November 2021 82721.833433
2021-12-31 December 2021 88457.167031
2022-01-31 January 2022 83521.903374
2022-02-28 February 2022 77111.163966
2022-03-31 March 2022 89020.492891
2022-04-30 April 2022 84398.869759
2022-05-31 May 2022 87129.254278
2022-06-30 June 2022 77127.818961
2022-07-31 July 2022 66858.934718
2022-08-31 August 2022 82171.650541
2022-09-30 September 2022 81889.850658
2022-10-31 October 2022 85506.751473
2022-11-30 November 2022 43938.951674
I am then plotting the data using the following:
figure = px.histogram(df,
y="MONTH",
x="VALUE",
color="YEAR",
barmode="group",
text_auto=True,
height=1000,
category_orders={"MONTH": list(calendar.month_name[1:])
}
)
figure.update_layout(
title="Test figure",
title_x=0.5,
xaxis_tickfont_size=14,
yaxis=dict(
title=None,
titlefont_size=16,
tickfont_size=14,
),
xaxis=dict(
title="LABEL"
),
bargap=0.65, # gap between bars of adjacent location coordinates.
)
figure.update_traces(textangle=0, textposition="outside", cliponaxis=False, texttemplate='%{x:.3f}')
Which results in a figure like this:
What I am trying to achieve is adding some forecasted values for the current month and remaining month of the year. This implies the dataframe to look like the following:
MONTH YEAR VALUE
2021-01-31 January 2021 108222.870075
2021-02-28 February 2021 83786.794785
2021-03-31 March 2021 88548.563611
2021-04-30 April 2021 85295.114970
2021-05-31 May 2021 89774.342922
2021-06-30 June 2021 86139.596102
2021-07-31 July 2021 90461.141199
2021-08-31 August 2021 90309.096285
2021-09-30 September 2021 88426.021444
2021-10-31 October 2021 90145.682254
2021-11-30 November 2021 82721.833433
2021-12-31 December 2021 88457.167031
2022-01-31 January 2022 83521.903374
2022-02-28 February 2022 77111.163966
2022-03-31 March 2022 89020.492891
2022-04-30 April 2022 84398.869759
2022-05-31 May 2022 87129.254278
2022-06-30 June 2022 77127.818961
2022-07-31 July 2022 66858.934718
2022-08-31 August 2022 82171.650541
2022-09-30 September 2022 81889.850658
2022-10-31 October 2022 85506.751473
2022-11-30 November 2022 67258.9646
2022-12-30 December 2022 936465.654464
Where November and December 2022 values are the forecast.
I would like to plot them using the same type of histogram presented above, but identify the forecasted values in a different shade of red.
Any ideas, about where to start ? Let me know if anything is unclear or if extra data are required to illustrate my problem.
Thank you for your time and help.