Skip to content

Commit

Permalink
Add support for creating line plot
Browse files Browse the repository at this point in the history
  • Loading branch information
bikegeek committed Mar 31, 2024
1 parent 2f7118e commit 945cdb8
Showing 1 changed file with 68 additions and 36 deletions.
104 changes: 68 additions & 36 deletions metplotpy/plots/tcmpr_plots/box/tcmpr_point.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
import os
from datetime import datetime

import plotly.graph_objects as go

from metplotpy.plots import util
from metplotpy.plots.tcmpr_plots.box.tcmpr_box_point import TcmprBoxPoint
from metplotpy.plots.tcmpr_plots.tcmpr_series import TcmprSeries


class TcmprPoint(TcmprBoxPoint):
def __init__(self, config_obj, column_info, col, case_data, input_df, baseline_data):
super().__init__(config_obj, column_info, col, case_data, input_df, baseline_data)
print("--------------------------------------------------------")
print(f"Plotting POINT time series by {self.config_obj.series_val_names[0]}")
def __init__(self, config_obj, column_info, col, case_data, input_df, baseline_data, stat_name):
super().__init__(config_obj, column_info, col, case_data, input_df, baseline_data, stat_name)
# Set up Logging
self.point_logger = util.get_common_logger(self.config_obj.log_level, self.config_obj.log_filename)

self._adjust_titles()
self.series_list = self._create_series(self.input_df)
self.point_logger.info("--------------------------------------------------------")
self.point_logger.info(f"Plotting POINT time series by {self.config_obj.series_val_names[0]}")
start = datetime.now()

self._adjust_titles(stat_name)
self.series_list = self._create_series(self.input_df, stat_name)
self.case_data = None
self.cur_baseline = baseline_data['cur_baseline']
self.cur_baseline_data = baseline_data['cur_baseline_data']
self._init_hfip_baseline_for_plot()

if self.config_obj.prefix is None or len(self.config_obj.prefix) == 0:
self.plot_filename = f"{self.config_obj.plot_dir}{os.path.sep}{self.config_obj.list_stat_1[0]}_pointplot.png"
self.plot_filename = f"{self.config_obj.plot_dir}{os.path.sep}{stat_name}_pointplot.png"
else:
self.plot_filename = f"{self.config_obj.plot_dir}{os.path.sep}{self.config_obj.prefix}_pointplot.png"

# remove the old file if it exist
self.plot_filename = f"{self.config_obj.plot_dir}{os.path.sep}{self.config_obj.prefix}_{stat_name}_pointplot.png"
# remove the old file if it exists
if os.path.exists(self.plot_filename):
os.remove(self.plot_filename)
self._create_figure()

def _adjust_titles(self):
self.point_logger.info(f"Finished generating the TCMPR points in {datetime.now() - start} ms")

def _adjust_titles(self, stat_name):
if self.yaxis_1 is None or len(self.yaxis_1) == 0:
self.yaxis_1 = self.config_obj.list_stat_1[0] + '(' + self.col['units'] + ')'
self.yaxis_1 = stat_name + '(' + self.col['units'] + ')'

if self.title is None or len(self.title) == 0:
self.title = 'Point Plots of ' + self.col['desc'] + ' by ' \
Expand All @@ -57,28 +64,53 @@ def _draw_series(self, series: TcmprSeries) -> None:
boxpoints = 'all'

# create a trace
self.figure.add_trace(
go.Box(x=series.series_data['LEAD_HR'],
y=series.series_data['PLOT'],
mean=series.series_points['mean'],
notched=self.config_obj.box_notch,
line=line_color,
fillcolor=fillcolor,
name=series.user_legends,
showlegend=True,
# quartilemethod='linear', #"exclusive", "inclusive", or "linear"
boxmean=self.config_obj.box_avg,
boxpoints=boxpoints, # outliers, all, False
pointpos=0,
marker=dict(size=4,
color=marker_color,

# boxplot, when connect_points is False in config file

if not self.config_obj.connect_points:
self.figure.add_trace(
go.Box(x=series.series_data['LEAD_HR'],
y=series.series_data['PLOT'],
mean=series.series_points['mean'],
notched=self.config_obj.box_notch,
line=line_color,
fillcolor=fillcolor,
name=series.user_legends,
showlegend=True,
boxmean=self.config_obj.box_avg,
boxpoints=boxpoints, # outliers, all, False
pointpos=0,
marker=dict(size=4,
color=marker_color,
line=dict(
width=1,
color=marker_line_color
),
symbol=marker_symbol,
),
jitter=0
),
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(
width=1,
color=marker_line_color
),
symbol=marker_symbol,
),
jitter=0
),
secondary_y=series.y_axis != 1
)
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)

0 comments on commit 945cdb8

Please sign in to comment.