From a4895785ea974b6a3d1ac49a5ff9edaea22bd365 Mon Sep 17 00:00:00 2001 From: bikegeek Date: Sun, 31 Mar 2024 18:05:51 -0600 Subject: [PATCH] Refactor to allow user to create either a scatter or line plot. Decrease opacity to enable better visualization of overlapping points --- .../plots/tcmpr_plots/box/tcmpr_point.py | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/metplotpy/plots/tcmpr_plots/box/tcmpr_point.py b/metplotpy/plots/tcmpr_plots/box/tcmpr_point.py index a988da1e..ecbc737a 100755 --- a/metplotpy/plots/tcmpr_plots/box/tcmpr_point.py +++ b/metplotpy/plots/tcmpr_plots/box/tcmpr_point.py @@ -66,8 +66,39 @@ def _draw_series(self, series: TcmprSeries) -> None: # create a trace # boxplot, when connect_points is False in config file - - if not self.config_obj.connect_points: + if 'point' in self.config_obj.plot_type_list: + if self.config_obj.connect_points: + # line plot + mode = 'lines+markers' + else: + # points only + mode = 'markers' + # Create a point plot + self.figure.add_trace( + go.Scatter(x=series.series_data['LEAD_HR'], + y=series.series_points['mean'], + showlegend=True, + mode=mode, + name=self.config_obj.user_legends[series.idx], + marker=dict( + color=marker_line_color, + size=8, + opacity=0.7, + line=dict( + color=self.config_obj.colors_list[series.idx], + width=1 + ) + ), + ), + secondary_y=series.y_axis != 1 + ) + + # When a line plot is requested, connect any gaps + if self.config_obj.connect_points: + self.figure.update_traces(connectgaps=True) + + else: + # Boxplot self.figure.add_trace( go.Box(x=series.series_data['LEAD_HR'], y=series.series_data['PLOT'], @@ -92,25 +123,4 @@ def _draw_series(self, series: TcmprSeries) -> None: ), secondary_y=series.y_axis != 1 ) - else: - # Create a point plot - self.figure.add_trace( - go.Scatter(x=series.series_data['LEAD_HR'], - y=series.series_points['mean'], - showlegend=True, - mode='lines+markers', - name=self.config_obj.user_legends[series.idx], - marker=dict( - color=marker_line_color, - size=8, - line=dict( - color=self.config_obj.colors_list[series.idx], - width=1 - ) - ), - ), - secondary_y=series.y_axis != 1 - ) - # Connect any gaps, so we always have line plot(s) - self.figure.update_traces(connectgaps=True)