-
Notifications
You must be signed in to change notification settings - Fork 0
Add kwargs to as plots #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed1374e
🎨 new arguments to sensitivity analysis plots
Tesshub 05a0922
✅ tests of plots with plot_kwargs and custom titles
Tesshub b0ce064
🎨✅ fixed range of colours for S2 matrix plots (issue #127)
Tesshub cd21083
🎨✅ scatter kwargs added too
Tesshub d7c4550
✏️👀 typo correction for eagle eyes
Tesshub b594e55
✏️👀 typo correction for eagle eyes
Tesshub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,6 +213,7 @@ def salib_plot_bar( | |
| reference_time_series: pd.Series = None, | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwarg, | ||
| ): | ||
| """ | ||
|
|
@@ -256,13 +257,16 @@ def salib_plot_bar( | |
| **analyse_kwarg, | ||
| )[f"{method}_{indicator}"] | ||
|
|
||
| _kwargs = dict(plot_kwargs or {}) | ||
| effective_title = _kwargs.pop("title", title) | ||
| return plot_bars( | ||
| pd.Series( | ||
| data=res[sensitivity_metric], | ||
| index=[par.name for par in self.sampler.sample.parameters], | ||
| name=f"{sensitivity_metric} {unit}", | ||
| ).sort_values(), | ||
| title=title, | ||
| title=effective_title, | ||
| **_kwargs, | ||
| ) | ||
|
|
||
| def salib_plot_dynamic_metric( | ||
|
|
@@ -277,6 +281,7 @@ def salib_plot_dynamic_metric( | |
| reference_time_series: pd.Series = None, | ||
| title: str = None, | ||
| stacked: bool = False, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwarg, | ||
| ): | ||
| """ | ||
|
|
@@ -323,7 +328,11 @@ def salib_plot_dynamic_metric( | |
| index=res.index, | ||
| ) | ||
|
|
||
| return plot_dynamic_metric(metrics, sensitivity_metric, unit, title, stacked) | ||
| _kwargs = dict(plot_kwargs or {}) | ||
| effective_title = _kwargs.pop("title", title) | ||
| return plot_dynamic_metric( | ||
| metrics, sensitivity_metric, unit, effective_title, stacked, **_kwargs | ||
| ) | ||
|
|
||
| def salib_plot_matrix( | ||
| self, | ||
|
|
@@ -333,6 +342,8 @@ def salib_plot_matrix( | |
| reference_time_series: pd.Series = None, | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| fixed_range: bool = True, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwarg, | ||
| ): | ||
| """ | ||
|
|
@@ -376,7 +387,15 @@ def salib_plot_matrix( | |
| )[f"{method}_{indicator}"] | ||
|
|
||
| parameter_names = [p.name for p in self.sampler.sample.parameters] | ||
| return plot_s2_matrix(result, parameter_names, title=title) | ||
| _kwargs = dict(plot_kwargs or {}) | ||
| effective_title = _kwargs.pop("title", title) | ||
| return plot_s2_matrix( | ||
| result, | ||
| parameter_names, | ||
| title=effective_title, | ||
| fixed_range=fixed_range, | ||
| **_kwargs, | ||
| ) | ||
|
|
||
|
|
||
| class SobolSanalysis(Sanalysis): | ||
|
|
@@ -453,6 +472,7 @@ def plot_bar( | |
| unit: str = "", | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwargs, | ||
| ): | ||
| return super().salib_plot_bar( | ||
|
|
@@ -464,6 +484,7 @@ def plot_bar( | |
| reference_time_series=reference_time_series, | ||
| agg_method_kwarg=agg_method_kwarg, | ||
| title=title, | ||
| plot_kwargs=plot_kwargs, | ||
| calc_second_order=calc_second_order, | ||
| **analyse_kwargs, | ||
| ) | ||
|
|
@@ -479,6 +500,7 @@ def plot_dynamic_metric( | |
| agg_method_kwarg: dict = None, | ||
| calc_second_order: bool = True, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| ): | ||
| return super().salib_plot_dynamic_metric( | ||
| indicator=indicator, | ||
|
|
@@ -492,6 +514,7 @@ def plot_dynamic_metric( | |
| calc_second_order=calc_second_order, | ||
| stacked=True, | ||
| title=title, | ||
| plot_kwargs=plot_kwargs, | ||
| ) | ||
|
|
||
| def plot_s2_matrix( | ||
|
|
@@ -501,6 +524,8 @@ def plot_s2_matrix( | |
| reference_time_series: pd.Series = None, | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| fixed_range: bool = True, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwargs, | ||
| ): | ||
| return super().salib_plot_matrix( | ||
|
|
@@ -510,6 +535,8 @@ def plot_s2_matrix( | |
| reference_time_series=reference_time_series, | ||
| agg_method_kwarg=agg_method_kwarg, | ||
| title=title, | ||
| fixed_range=fixed_range, | ||
| plot_kwargs=plot_kwargs, | ||
| **analyse_kwargs, | ||
| ) | ||
|
|
||
|
|
@@ -581,6 +608,7 @@ def plot_scatter( | |
| unit: str = "", | ||
| scaler: float = 100, | ||
| autosize: bool = True, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwargs, | ||
| ): | ||
| cache_key = (indicator, method, "None") | ||
|
|
@@ -596,12 +624,15 @@ def plot_scatter( | |
| )[f"{method}_{indicator}"] | ||
| self._analysis_cache[cache_key] = {f"{method}_{indicator}": result} | ||
|
|
||
| _kwargs = dict(plot_kwargs or {}) | ||
| effective_title = _kwargs.pop("title", title) | ||
| return plot_morris_scatter( | ||
| result, | ||
| title=title, | ||
| title=effective_title, | ||
| unit=unit, | ||
| scaler=scaler, | ||
| autosize=autosize, | ||
| **_kwargs, | ||
| ) | ||
|
|
||
| def plot_bar( | ||
|
|
@@ -613,6 +644,7 @@ def plot_bar( | |
| unit: str = "", | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwargs, | ||
| ): | ||
| return super().salib_plot_bar( | ||
|
|
@@ -624,6 +656,7 @@ def plot_bar( | |
| reference_time_series=reference_time_series, | ||
| agg_method_kwarg=agg_method_kwarg, | ||
| title=title, | ||
| plot_kwargs=plot_kwargs, | ||
| **analyse_kwargs, | ||
| ) | ||
|
|
||
|
|
@@ -637,6 +670,7 @@ def plot_dynamic_metric( | |
| unit: str = "", | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| ): | ||
| return super().salib_plot_dynamic_metric( | ||
| indicator, | ||
|
|
@@ -648,6 +682,7 @@ def plot_dynamic_metric( | |
| agg_method_kwarg, | ||
| reference_time_series, | ||
| title, | ||
| plot_kwargs=plot_kwargs, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -709,6 +744,7 @@ def plot_bar( | |
| unit: str = "", | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwargs, | ||
| ): | ||
| return super().salib_plot_bar( | ||
|
|
@@ -720,6 +756,7 @@ def plot_bar( | |
| reference_time_series=reference_time_series, | ||
| agg_method_kwarg=agg_method_kwarg, | ||
| title=title, | ||
| plot_kwargs=plot_kwargs, | ||
| **analyse_kwargs, | ||
| ) | ||
|
|
||
|
|
@@ -733,6 +770,7 @@ def plot_dynamic_metric( | |
| unit: str = "", | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| ): | ||
| return super().salib_plot_dynamic_metric( | ||
| indicator=indicator, | ||
|
|
@@ -745,6 +783,7 @@ def plot_dynamic_metric( | |
| reference_time_series=reference_time_series, | ||
| stacked=True, | ||
| title=title, | ||
| plot_kwargs=plot_kwargs, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -803,6 +842,7 @@ def plot_bar( | |
| unit: str = "", | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| **analyse_kwargs, | ||
| ): | ||
| return super().salib_plot_bar( | ||
|
|
@@ -814,6 +854,7 @@ def plot_bar( | |
| reference_time_series=reference_time_series, | ||
| agg_method_kwarg=agg_method_kwarg, | ||
| title=title, | ||
| plot_kwargs=plot_kwargs, | ||
| **analyse_kwargs, | ||
| ) | ||
|
|
||
|
|
@@ -827,6 +868,7 @@ def plot_dynamic_metric( | |
| unit: str = "", | ||
| agg_method_kwarg: dict = None, | ||
| title: str = None, | ||
| plot_kwargs: dict = None, | ||
| ): | ||
| return super().salib_plot_dynamic_metric( | ||
| indicator=indicator, | ||
|
|
@@ -839,15 +881,25 @@ def plot_dynamic_metric( | |
| reference_time_series=reference_time_series, | ||
| stacked=True, | ||
| title=title, | ||
| plot_kwargs=plot_kwargs, | ||
| ) | ||
|
|
||
|
|
||
| def _apply_figure_kwargs(fig, **kwargs): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est un peu moche ça non ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on laisse comme ça pour le moment :) |
||
| for key, val in kwargs.items(): | ||
| try: | ||
| fig.update_layout(**{key: val}) | ||
| except ValueError: | ||
| fig.update_traces(**{key: val}) | ||
|
|
||
|
|
||
| def plot_dynamic_metric( | ||
| metrics: pd.DataFrame, | ||
| metric_name: str = "", | ||
| unit: str = "", | ||
| title: str = None, | ||
| stacked: bool = False, | ||
| **plot_kwargs, | ||
| ): | ||
| fig = go.Figure() | ||
| for param in metrics.columns: | ||
|
|
@@ -866,12 +918,16 @@ def plot_dynamic_metric( | |
| xaxis_title="Time", | ||
| yaxis_title=f"{metric_name} {unit}", | ||
| ) | ||
| _apply_figure_kwargs(fig, **plot_kwargs) | ||
|
|
||
| return fig | ||
|
|
||
|
|
||
| def plot_bars( | ||
| sensitivity_results: pd.Series, title: str = None, error: pd.Series = None | ||
| sensitivity_results: pd.Series, | ||
| title: str = None, | ||
| error: pd.Series = None, | ||
| **plot_kwargs, | ||
| ): | ||
| error = {} if error is None else dict(type="data", array=error.values) | ||
| fig = go.Figure() | ||
|
|
@@ -890,6 +946,7 @@ def plot_bars( | |
| xaxis_title="Parameters", | ||
| yaxis_title=f"{sensitivity_results.name}", | ||
| ) | ||
| _apply_figure_kwargs(fig, **plot_kwargs) | ||
|
|
||
| return fig | ||
|
|
||
|
|
@@ -900,6 +957,7 @@ def plot_morris_scatter( | |
| unit: str = "", | ||
| scaler: float = 100, | ||
| autosize: bool = True, | ||
| **plot_kwargs, | ||
| ) -> go.Figure: | ||
| """ | ||
| Plot a Morris sensitivity analysis scatter plot using μ* and σ. | ||
|
|
@@ -986,6 +1044,7 @@ def plot_morris_scatter( | |
| yaxis_title=f"Standard deviation of elementary effects σ [{unit}]", | ||
| yaxis_range=[-0.1 * y_max, y_max], | ||
| ) | ||
| _apply_figure_kwargs(fig, **plot_kwargs) | ||
|
|
||
| return fig | ||
|
|
||
|
|
@@ -995,17 +1054,22 @@ def plot_s2_matrix( | |
| param_names: list[str], | ||
| title: str = "Sobol 2nd-order interactions (S2)", | ||
| colorscale: str = "Reds", | ||
| fixed_range: bool = True, | ||
| **plot_kwargs, | ||
| ): | ||
| df_S2 = pd.DataFrame(result["S2"], index=param_names, columns=param_names) | ||
|
|
||
| zmin = -1 if fixed_range else df_S2.values.min() | ||
| zmax = 1 if fixed_range else df_S2.values.max() | ||
|
|
||
| fig = go.Figure( | ||
| data=go.Heatmap( | ||
| z=df_S2.values, | ||
| x=df_S2.columns, | ||
| y=df_S2.index, | ||
| colorscale=colorscale, | ||
| zmin=0, | ||
| zmax=df_S2.values.max(), | ||
| zmin=zmin, | ||
| zmax=zmax, | ||
| colorbar=dict(title="S2"), | ||
| text=df_S2.round(3).astype(str), | ||
| texttemplate="%{text}", | ||
|
|
@@ -1017,5 +1081,6 @@ def plot_s2_matrix( | |
| xaxis_title="Parameter", | ||
| yaxis_title="Parameter", | ||
| ) | ||
| _apply_figure_kwargs(fig, **plot_kwargs) | ||
|
|
||
| return fig | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.