Create distribution plot - #13985
Conversation
3b47d66 to
e78c16a
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the ERT GUI plotting to consolidate histogram/KDE functionality into a single Distribution plot, adding plot-option controls to stack multiple ensembles in one view (with opacity) rather than using separate plot tabs.
Changes:
- Replace separate “Histogram” and “Gaussian KDE” plot tabs with a unified Distribution plot supporting histogram/KDE/rug options and density vs count mode.
- Add a new
DistributionOptionscontrol widget and wire its state intoPlotContextviaPlotWindow.fetch_data(). - Refactor
PlotToolshelpers (snake_case naming + small utility methods) and adjust plot layout engine configuration.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ert/gui/plotting/widgets/plot_widget.py | Switch Matplotlib layout engine to constrained. |
| src/ert/gui/plotting/widgets/plot_controls/distribution_options.py | New plot-control widget for distribution plot options (histogram/KDE/rug + density/count). |
| src/ert/gui/plotting/widgets/plot_controls/init.py | Export DistributionOptions. |
| src/ert/gui/plotting/utils/plot_tools.py | Rename helpers to snake_case and add set_title, set_labels_for_axes_from_context, remove_spines. |
| src/ert/gui/plotting/utils/plot_context.py | Add distribution-plot state to PlotContext (histogram/rug/KDE/by_density). |
| src/ert/gui/plotting/plot_window.py | Remove histogram/KDE tabs; add DistributionOptions widget and propagate its state into PlotContext. |
| src/ert/gui/plotting/ert_plots/distribution.py | Implement the new stacked distribution plot (histogram/KDE/rug; density vs count). |
1d37447 to
9c17929
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 8 comments.
Comments suppressed due to low confidence (1)
src/ert/gui/plotting/plot_window.py:38
ert.gui.plotting.ert_plotsis still re-exportingGaussianKDEPlot/HistogramPlotfrom modules that are deleted in this PR, which will raiseImportErrorwhen this file importsDistributionPlotfrom that package. Updatesrc/ert/gui/plotting/ert_plots/__init__.py(and any remaining references) to stop importing/re-exporting the removed plots.
from ert.gui.plotting.ert_plots import (
CrossEnsembleStatisticsPlot,
DistributionPlot,
MisfitsPlot,
StatisticsPlot,
StdDevPlot,
)
138bffd to
d91fadb
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13985 +/- ##
==========================================
+ Coverage 91.97% 91.99% +0.01%
==========================================
Files 484 484
Lines 33644 33798 +154
==========================================
+ Hits 30945 31093 +148
- Misses 2699 2705 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
|
d91fadb to
6a40c4f
Compare
| self._plot_distribution( | ||
| figure, plot_context, ensemble_to_data_map, plot_context.by_density | ||
| ) |
|
Screenshots differ from baselines. A baseline update PR has been prepared: equinor/ert-testdata#48 |
206f834 to
03f25b8
Compare
|
Marking as blocked until GKDE clarification |
9eec127 to
c731588
Compare
|
Screenshots differ from baselines. A baseline update PR has been prepared: equinor/ert-testdata#82 |
91c74f3 to
adb112e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Suppressed comments (3)
src/ert/gui/plotting/ert_plots/distribution.py:94
- With Histogram unchecked and Gaussian KDE checked, this still creates a twin histogram axis.
_scale_count_axes()and_finalize_axes()then show and scale aCount (Histogram)axis even though no histogram was requested. Gate twin-axis creation, count-axis scaling, and the dual labels on both options being enabled; a KDE-only plot should use only the density axis.
use_twin_axes = self._gkde_plot
histogram_axes = main_axes.twinx() if use_twin_axes else main_axes
src/ert/gui/plotting/widgets/plot_widget.py:156
- The PR states that it resolves #13769 by reducing plotter padding, but this file still leaves the
QVBoxLayoutdefault margins/spacing in place and retains the explicit 8-pixel spacer. The added reset logic does not address that issue; apply the zero-margin/zero-spacing layout change described in #13769.
# Some figures contain twinaxes
# Resetting the xscale to linear for all axes
# to avoid log scale issues when re-plotting after a log scale plot
src/ert/gui/plotting/widgets/plot_controls/distribution_options.py:60
- This introduces user-facing distribution controls and substantially changes the Distribution plot, but no corresponding
.rstuser documentation was added or updated. Add usage documentation for the three toggles and explain the replacement/removal of the standalone Gaussian KDE behavior, as required for user-facing changes in this repository.
self._distribution_options = CollapsibleSection(
"Distribution options",
create_group_layout(
[
self._histogram,
self._gkde,
self._rug_plot,
]
),
expanded=True,
|
I suggest the following changes to the tick-boxes: |
|
|
|
It could be a tick option to have stacked histogram plots, but that is fine to save for a different PR (more valid if the Histogram tab should be removed) |
@berland Stacked as in the previous functionality or as in stacked in same figure? |
As in previous functionality, to easen up removal of the (old) tab. |
Preperations for the new plot. The different options will allow the user to toggle the plot types to add to the figure and what type of axis to display. Each plot option contains helper text Intention is to replace the single line scatter-points with rug plot to better visualize the distribution
Prep. for new DistributionPlot The DistributionPlot will not be able to use finalizePlot(), due to it having multiple axis and grid. Want to allow users to modify the figure, e.g changing labels, toggle grid etc. Extracting methods from finalizePlot() to standalone methods, such that implementation can try to align as much as possible with the finalizePlot()-flow
Prep. for new DistributionPlot The new DistributionPlot will use multiple axis, so need to be able to reset all axes at reset(). Otherwise will get log-scale error when un-checking the log-scale checkbox.
DistributionPlot implementation Removed GKDE, including references in plot_window-tests Added DistributionPlot and corresponding tests. The plot implements three methods of plotting the distribution: - Gaussian KDE - Overlapping Histogram (y-axis can be set to count or density) - Rug plots for to visualize the raw datapoints. Behaviour of the plot changes depending of what plots are toggled. If GKDE or Hist. is turned off, the rugplots will act as the main window otherwise, they will be a supporting plot underneath the "main" plot-window If multiple ensembles are selected the overlapping histograms can become muddied and hard to distinquish. This is not a common use-case as most users will only select first and last. No screenshot-test added, only unit testing. Plot will likely undergo refactoring/updates, so will await screenshot-testing until "stable". Note: Cannot remove original HistogramPlot as of now, as the new plot can not handle categorical data yet.

Issue
Resolves #13952
Resolves #13769
Resolves #13950
Approach
We had three ways of plotting the distribution,
Gaussian KDE,HistogramandDistribution. To improve the visualization have attempted to combine these and introduce more customizbility to the user. The assumption made for the use-case is that it is first and last iterations that is the most interesting (ensemble selected =iter-0anditer-3)Histogram:
matplotlibsrtfunctionality. Similar to original code, but can lead to different bin width Use matplotlib method for bin creation for histogram #13961Gaussian KDE:
Works similar as before, but now potentially plotted on top of the histogram. Does not allow log scale. Changing scale post evaluation looks off
Rug plot (old distribution plot):
No longer scatter plot in a single line, now rug plots underneath the "main plot" (contains histogram and the gkde). Illustrates groupings better. Is displayed on the x axis rather than y and shares axis as the "main plot", works with log-scale as before. Decided not to have a shared axis for better readability and to illustrate the ensembles grouping.
Note: Similar to histogram, could benefit from another palette as yellow is hard to read
No handling of categorical data, so could not remove
HIstogramPlotas of now, onlyGaussianKDEgit rebase -i main --exec 'just rapid-tests')When applicable