From a4da6be7ad77b9b1ca223c797ba06477cf086f38 Mon Sep 17 00:00:00 2001 From: Kajetan Puchalski Date: Mon, 21 Aug 2023 16:59:58 +0100 Subject: [PATCH] wp.notebook: WorkloadNotebookPlotter: Ensure consistent ordering in lines_px --- setup.cfg | 1 + wp/notebook.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index d64ec6b..68b96c8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,7 @@ install_requires = pdoc==14.0.0 xarray==2023.1.0 datashader==0.15.1 + kaleido==0.2.1 [options.extras_require] all = diff --git a/wp/notebook.py b/wp/notebook.py index 1a80603..562cd06 100644 --- a/wp/notebook.py +++ b/wp/notebook.py @@ -1816,7 +1816,7 @@ def gmean_bars(self, df: pd.DataFrame, x: str = 'stat', y: str = 'value', color: return data_table - def lines_px(self, df: pd.DataFrame, x: str = 'iteration', y: str = 'value', + def lines_px(self, df: pd.DataFrame, x: str = 'iteration', y: str = 'value', sort_cols=['iteration'], color: str = 'tag', facet_col: Optional[str] = None, facet_col_wrap: int = 2, height: int = 600, width: Optional[int] = None, title: Optional[str] = None, scale_y: bool = False, renderer: str = 'iframe'): @@ -1831,12 +1831,16 @@ def lines_px(self, df: pd.DataFrame, x: str = 'iteration', y: str = 'value', :param color: Column denoting how to split the data into lines :param facet_col: Column denoting how to split the plot into facets :param facet_col_wrap: Number of facet column in one row of the plot + :param sort_cols: Columns to sort the `df` by apart from `tag` :param title: Displayed title of the plot :param width: Plot width :param height: Plot height :param scale_y: Whether the y axis should maintain the same scale across facets :param renderer: Plotly express renderer to be used """ + + df['order_tag'] = df['tag'].map(lambda x: self.ana.tags.index(x)) + df = df.sort_values(by=['order_tag', *sort_cols]) fig = px.line(df, x=x, y=y, color=color, facet_col=facet_col, facet_col_wrap=facet_col_wrap, height=height, width=width, title=title) if not scale_y: