Add editable axis/title labels from plot - #13992
Conversation
There was a problem hiding this comment.
Pull request overview
Enables in-plot editing of Matplotlib axis labels in the ERT GUI by making axis label artists pickable, emitting a Qt signal when a label is clicked, and opening an edit dialog in the plot window that persists changes via the active PlotConfig history.
Changes:
- Add pick handling in
PlotWidgetto detect clicks on x/y axis label artists and emit an edit-request signal. - Add an edit flow in
PlotWindowusingQInputDialog, applying accepted label changes viaPlotCustomizer. - Allow
PlotConfigx/y label setters to acceptNone, and add unit tests covering the new signal + config update behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/ert/unit_tests/gui/tools/plot/test_plot_window.py | Adds unit tests for axis-label click signal emission and PlotCustomizer.set_axis_label() updating PlotConfig. |
| src/ert/gui/plotting/widgets/plot_widget.py | Connects Matplotlib pick_event, enables picking for axis labels, and emits axisLabelEditRequested. |
| src/ert/gui/plotting/utils/plot_config.py | Updates x/y label setters to accept `str |
| src/ert/gui/plotting/plot_window.py | Listens for axisLabelEditRequested and opens a pre-filled input dialog to edit/apply axis labels. |
| src/ert/gui/plotting/customization_dialog/customize_plot_dialog.py | Adds PlotCustomizer.set_axis_label() to write label changes into PlotConfigHistory and refresh customization UI state. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #13992 +/- ##
==========================================
- Coverage 91.63% 91.57% -0.07%
==========================================
Files 487 487
Lines 34380 34451 +71
==========================================
+ Hits 31505 31549 +44
- Misses 2875 2902 +27
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Screenshots differ from baselines. A baseline update PR has been prepared: equinor/ert-testdata#52 |
0295a76 to
8ca5c7b
Compare
|
Could we also add two buttons (Change x-label, Change y-label) to |
Sounds good! I'll do that. Sidenote: also noticed that the Limits tab looks awkward in customization widget, the text boxes are unnaturally tall. |
Think the formatting is due to how its set initially. In general, the customization widget has a lot of issues, so I think we should have a move limits to I think I would split this PR in two, labels and limits, to prevent scope creep now that we can add more buttons. If we finish labels with this PR, then we can repeat the axis-click + additional buttons + customization widget field/tab removal, but for limits Edit: Could prob add title too? |
I agree! I'll just move that limit related commit then. |
| self.update_plot_config(plot_config) | ||
|
|
||
| def update_plot_config(self, plot_config: PlotConfig) -> None: | ||
| history = self._get_plot_config_history() | ||
| history.apply_changes(plot_config) | ||
| self._emit_changed_signal() |
There was a problem hiding this comment.
This was a temp solution needed before removal of the CustomizationDialog or could this be skipped?
There was a problem hiding this comment.
It's like this to keep current per key plotting behaviour so that changes for titles remain when clicking between keys.
| self._change_x_label = QPushButton("Edit x-label") | ||
| self._change_x_label.setObjectName("change_x_label_button") | ||
| self._change_x_label.clicked.connect( | ||
| lambda: self.axisLabelEditRequested.emit("x") | ||
| ) | ||
|
|
||
| self._change_y_label = QPushButton("Edit y-label") | ||
| self._change_y_label.setObjectName("change_y_label_button") | ||
| self._change_y_label.clicked.connect( | ||
| lambda: self.axisLabelEditRequested.emit("y") | ||
| ) | ||
|
|
||
| self._change_title = QPushButton("Edit title") | ||
| self._change_title.setObjectName("change_title_button") | ||
| self._change_title.clicked.connect(self.titleEditRequested.emit) |
There was a problem hiding this comment.
Could we reduce the duplication of code somehow? If fix leads to unnecessarily difficult to read code, then skip
There was a problem hiding this comment.
Can absolutely be done 👍
There was a problem hiding this comment.
Done in recent commit
|
Could you add a couple of screenshots to display functionality and buttons? |
23d3daa to
c5cb2ea
Compare
|
It is not obvious to me that it is possible to click on the axis labels and title to edit them. Is there an easy way to add some effect or something similar that shows that these are editable by clicking on them? E.g changing fontsize when hovered or background color or cursor type on hover etc. |
Good point! Maybe actually this can be in a smaller separate PR? I will have an upcoming one for the limits as well. |
Users need a direct way to customize the x and y axis labels from the plot.
| self._change_x_label = create_edit_button( | ||
| "x-label", | ||
| lambda: self.axisLabelEditRequested.emit("x"), | ||
| ) | ||
| self._change_y_label = create_edit_button( | ||
| "y-label", | ||
| lambda: self.axisLabelEditRequested.emit("y"), | ||
| ) | ||
| self._change_title = create_edit_button( | ||
| "title", | ||
| self.titleEditRequested.emit, | ||
| ) | ||
|
|
||
| edit_buttons = QWidget() | ||
| edit_buttons_layout = QHBoxLayout(edit_buttons) | ||
| edit_buttons_layout.setContentsMargins(0, 0, 0, 0) | ||
|
|
||
| for button in ( | ||
| self._change_x_label, | ||
| self._change_y_label, | ||
| self._change_title, | ||
| ): | ||
| edit_buttons_layout.addWidget(button) | ||
|
|
There was a problem hiding this comment.
for label, func in [ ("x-label", lambda: self.axisLabelEditRequested.emit("x")) ...]:
edit_buttons_layout.addWidget(create_edit_button(label, func)
There was a problem hiding this comment.
Much better, done! 👍
eilskra
left a comment
There was a problem hiding this comment.
Just had one refactor comment, bar that LGTM
Issue
Resolves #13999
Resolves #14006
Approach
Enable picking on the x- and y-axis labels and plot title after each render, and handle Matplotlib pick events on the canvas. Selecting one opens a pre-filled input dialog. Accepted changes are stored in the active key’s PlotConfig history and applied immediately through the existing refresh mechanism. Clearing the input restores the default text.
Also removes the axis-label and title controls from the customization style tab.
git rebase -i main --exec 'just rapid-tests')When applicable