diff --git a/metplotpy/plots/config/line_defaults.yaml b/metplotpy/plots/config/line_defaults.yaml index eb4dec362..595344c9f 100644 --- a/metplotpy/plots/config/line_defaults.yaml +++ b/metplotpy/plots/config/line_defaults.yaml @@ -94,6 +94,7 @@ xlab_offset: 2 xlab_size: 1 xlab_weight: 1 xlim: [] +xlim_step: 1 xtlab_decim: 0 xtlab_horiz: 0.5 xtlab_orient: 1 diff --git a/metplotpy/plots/line/line.py b/metplotpy/plots/line/line.py index af32e90ae..4eb8b59e1 100644 --- a/metplotpy/plots/line/line.py +++ b/metplotpy/plots/line/line.py @@ -310,43 +310,39 @@ def _draw_series(self, series: Series, x_points_index_adj: Union[list, None] = series.idx] == 'NONE'): error_y_visible = False + # switch x and y values for the vertical plot + error_x = {} + error_y = {} if self.config_obj.vert_plot is True: y_points, x_points_index_adj = x_points_index_adj, y_points + self._xaxis_limits() + self.figure.update_xaxes(autorange=False) - # add the plot - - # orient the confidence interval bars based on the vert_plot setting in - # the yaml configuration file. - if self.config_obj.vert_plot: - self.figure.add_trace( - go.Scatter(x=x_points_index_adj, - y=y_points, - showlegend=self.config_obj.show_legend[series.idx] == 1, - mode=self.config_obj.mode[series.idx], - textposition="top right", - name=self.config_obj.user_legends[series.idx], - connectgaps=self.config_obj.con_series[series.idx] == 1, - line={'color': self.config_obj.colors_list[series.idx], - 'width': self.config_obj.linewidth_list[series.idx], - 'dash': self.config_obj.linestyles_list[series.idx]}, - marker_symbol=self.config_obj.marker_list[series.idx], - marker_color=self.config_obj.colors_list[series.idx], - marker_line_color=self.config_obj.colors_list[series.idx], - marker_size=self.config_obj.marker_size[series.idx], - error_x={'type': 'data', + # Error bars for vertical plot + error_x = {'type': 'data', 'symmetric': False, 'array': series.series_points['dbl_up_ci'], 'arrayminus': series.series_points['dbl_lo_ci'], 'visible': error_y_visible, 'thickness': self.config_obj.linewidth_list[ series.idx]} - ), - secondary_y=series.y_axis != 1 - ) else: - self.figure.add_trace( - go.Scatter(x=x_points_index_adj, + # Error bars + error_y = { + 'type': 'data', + 'symmetric': False, + 'array': series.series_points['dbl_up_ci'], + 'arrayminus': series.series_points['dbl_lo_ci'], + 'visible': error_y_visible, + 'thickness': self.config_obj.linewidth_list[series.idx] + } + + # add the plot + # orient the confidence interval bars based on the vert_plot setting in + # the yaml configuration file. + self.figure.add_trace( + go.Scatter(x=x_points_index_adj, y=y_points, showlegend=self.config_obj.show_legend[series.idx] == 1, mode=self.config_obj.mode[series.idx], @@ -360,17 +356,13 @@ def _draw_series(self, series: Series, x_points_index_adj: Union[list, None] = marker_color=self.config_obj.colors_list[series.idx], marker_line_color=self.config_obj.colors_list[series.idx], marker_size=self.config_obj.marker_size[series.idx], - error_y={'type': 'data', - 'symmetric': False, - 'array': series.series_points['dbl_up_ci'], - 'arrayminus': series.series_points['dbl_lo_ci'], - 'visible': error_y_visible, - 'thickness': self.config_obj.linewidth_list[ - series.idx]} + error_x=error_x, + error_y=error_y ), - secondary_y=series.y_axis != 1 + secondary_y=series.y_axis != 1 ) + self.logger.info(f"Finished drawing the lines on the plot:" f" {datetime.now()}") @@ -455,25 +447,25 @@ def _adjust_for_vertical(self, x_points_index: list) -> None: """ Switches x and y axis (creates a vertical plot) if needed - :param x_points_index: list of indexws for the original x -axis + :param x_points_index: list of indexes for the original x -axis """ self.logger.info(f"Begin switching x and y axis: {datetime.now()}") - odered_indy_label = self.config_obj.create_list_by_plot_val_ordering( + ordered_indy_label = self.config_obj.create_list_by_plot_val_ordering( self.config_obj.indy_label) if self.config_obj.vert_plot is True: self.figure.update_layout( yaxis={ 'tickmode': 'array', 'tickvals': x_points_index, - 'ticktext': odered_indy_label + 'ticktext': ordered_indy_label } - ) + ) else: self.figure.update_layout( xaxis={ 'tickmode': 'array', 'tickvals': x_points_index, - 'ticktext': odered_indy_label + 'ticktext': ordered_indy_label } ) @@ -573,9 +565,38 @@ def _add_legend(self) -> None: } }) + def _xaxis_limits(self) -> None: + """ + Apply limits on x axis if needed + especially when a vertical plot is requested + + step size by default is 1 if undefined /non-existent + + + step size must be integer value + """ + if len(self.config_obj.parameters['xlim']) > 0: + step = round(float(self.config_obj.parameters['xlim_step'])) + if step is None: + step = 1 + + # Convert string values to float, use numpy arange to + # generate a list of labels based on the min, max, and step values + # Round the min and max values to nearest integer + min_x= round(float(self.config_obj.parameters['xlim'][0])) + max_x= round(float(self.config_obj.parameters['xlim'][1])) + tick_labels = list(np.arange(min_x , max_x + step, step)) + + self.figure.update_layout( + xaxis={ + 'range': [min_x, max_x], + 'autorange':False, + 'tickvals':tick_labels} + ) + def _yaxis_limits(self) -> None: """ - Apply limits on y2 axis if needed + Apply limits on y axis if needed """ if len(self.config_obj.parameters['ylim']) > 0: self.figure.update_layout( @@ -583,6 +604,8 @@ def _yaxis_limits(self) -> None: self.config_obj.parameters['ylim'][1]], 'autorange': False}) + + def _y2axis_limits(self) -> None: """ Apply limits on y2 axis if needed diff --git a/metplotpy/plots/util.py b/metplotpy/plots/util.py index 2664f32df..4fe31399c 100644 --- a/metplotpy/plots/util.py +++ b/metplotpy/plots/util.py @@ -445,7 +445,7 @@ def filter_by_fixed_vars(input_df: pd.DataFrame, settings_dict: dict) -> pd.Data if len(valid_columns) == 0: print( - "No columns in data match what is requested. Input dataframe will be " + "No columns in data match what is requested for filtering by fixed variable. Input dataframe will be " "returned") return input_df