From 3b6f368b49b2e11510d34945124500b7a0aef980 Mon Sep 17 00:00:00 2001 From: remic Date: Thu, 30 Mar 2023 14:16:23 -0400 Subject: [PATCH 1/2] histograms is better for time series with missing values --- enacts/onset/maproom.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/enacts/onset/maproom.py b/enacts/onset/maproom.py index 35e89a8c2..593525b39 100644 --- a/enacts/onset/maproom.py +++ b/enacts/onset/maproom.py @@ -449,16 +449,14 @@ def onset_plots( ) # dash.no_update to leave the plat as-is and not show no data display onset_date_graph = pgo.Figure() onset_date_graph.add_trace( - pgo.Scatter( + pgo.Bar( x=onset_delta["T"].dt.year.values, - y=onset_delta["onset_delta"].dt.days.values, + y=onset_delta["onset_delta"].dt.days.where(lambda x: x > 0, other=0.1).values, customdata=(onset_delta["T"] + onset_delta["onset_delta"]).dt.strftime("%-d %B %Y"), hovertemplate="%{customdata}", name="", - line=pgo.scatter.Line(color="blue"), ) ) - onset_date_graph.update_traces(mode="lines", connectgaps=False) onset_date_graph.update_layout( xaxis_title="Year", yaxis_title=f"Onset Date in days since {search_start_month} {int(search_start_day)}", @@ -571,16 +569,16 @@ def cess_plots( ) # dash.no_update to leave the plat as-is and not show no data display cess_date_graph = pgo.Figure() cess_date_graph.add_trace( - pgo.Scatter( + pgo.Bar( x=cess_delta["T"].dt.year.values, - y=cess_delta["cess_delta"].squeeze().dt.days.values, + y=cess_delta["cess_delta"].squeeze().dt.days.where( + lambda x: x > 0, other=0.1 + ).values, customdata=(cess_delta["T"] + cess_delta["cess_delta"]).dt.strftime("%-d %B %Y"), hovertemplate="%{customdata}", name="", - line=pgo.scatter.Line(color="blue"), ) ) - cess_date_graph.update_traces(mode="lines", connectgaps=False) cess_date_graph.update_layout( xaxis_title="Year", yaxis_title=f"Cessation Date in days since {cess_start_month} {int(cess_start_day)}", @@ -726,7 +724,7 @@ def length_plots( return error_fig, error_fig, tab_style length_graph = pgo.Figure() length_graph.add_trace( - pgo.Scatter( + pgo.Bar( x=onset_delta["T"].dt.year.values, y=seasonal_length.squeeze().dt.days.values, customdata=np.stack(( @@ -735,10 +733,8 @@ def length_plots( ), axis=-1), hovertemplate="%{customdata[0]} to %{customdata[1]}", name="", - line=pgo.scatter.Line(color="blue"), ) ) - length_graph.update_traces(mode="lines", connectgaps=False) length_graph.update_layout( xaxis_title="Year", yaxis_title=f"Season Length in days", From cffb3a83d1fe4a6f518cd7a9ca8bccc8af2b4538 Mon Sep 17 00:00:00 2001 From: remic Date: Thu, 30 Mar 2023 14:31:57 -0400 Subject: [PATCH 2/2] explanations --- enacts/onset/maproom.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/enacts/onset/maproom.py b/enacts/onset/maproom.py index 593525b39..d4f4dfd8f 100644 --- a/enacts/onset/maproom.py +++ b/enacts/onset/maproom.py @@ -451,7 +451,12 @@ def onset_plots( onset_date_graph.add_trace( pgo.Bar( x=onset_delta["T"].dt.year.values, - y=onset_delta["onset_delta"].dt.days.where(lambda x: x > 0, other=0.1).values, + y=onset_delta["onset_delta"].dt.days.where( + # 0 is a both legitimate start for bars and data value + # but in that case 0 won't draw a bar, and the is nothing to hover + # this giving a dummy small height to draw a bar to hover + lambda x: x > 0, other=0.1 + ).values, customdata=(onset_delta["T"] + onset_delta["onset_delta"]).dt.strftime("%-d %B %Y"), hovertemplate="%{customdata}", name="", @@ -572,6 +577,9 @@ def cess_plots( pgo.Bar( x=cess_delta["T"].dt.year.values, y=cess_delta["cess_delta"].squeeze().dt.days.where( + # 0 is a both legitimate start for bars and data value + # but in that case 0 won't draw a bar, and the is nothing to hover + # this giving a dummy small height to draw a bar to hover lambda x: x > 0, other=0.1 ).values, customdata=(cess_delta["T"] + cess_delta["cess_delta"]).dt.strftime("%-d %B %Y"),