Skip to content

Commit 8bbe88f

Browse files
committed
Update PlotTools methods
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
1 parent 745d880 commit 8bbe88f

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/ert/gui/plotting/utils/plot_tools.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,23 @@ def finalize_plot(
9595

9696
PlotTools._setup_labels(plot_context, default_x_label, default_y_label)
9797

98-
plot_config = plot_context.plotConfig()
99-
axes.set_xlabel(plot_config.x_label()) # type: ignore
100-
axes.set_ylabel(plot_config.y_label()) # type: ignore
98+
PlotTools.set_labels_for_axes_from_context(axes, plot_context)
99+
101100
axes.set_xlim(auto=False)
102101
axes.set_ylim(auto=False)
103102

104-
axes.set_title(plot_config.title())
103+
PlotTools.set_title(axes, plot_context)
105104

106105
if plot_context.is_date_support_active():
107106
figure.autofmt_xdate()
108107

109-
for spine in ("right", "left", "top"):
110-
axes.spines[spine].set_visible(False)
108+
PlotTools.remove_spines(axes, ["right", "left", "top"])
109+
110+
@staticmethod
111+
def set_title(axes: Axes, plot_context: PlotContext) -> None:
112+
title = plot_context.plotConfig().title()
113+
if title is not None:
114+
axes.set_title(title)
111115

112116
@staticmethod
113117
def _setup_labels(
@@ -180,3 +184,16 @@ def _handle_event(event: Event) -> None:
180184
"motion_notify_event",
181185
_handle_event,
182186
)
187+
188+
@staticmethod
189+
def set_labels_for_axes_from_context(axes: Axes, plot_context: PlotContext) -> None:
190+
config = plot_context.plotConfig()
191+
if (x_label := config.x_label()) is not None:
192+
axes.set_xlabel(x_label)
193+
if (y_label := config.y_label()) is not None:
194+
axes.set_ylabel(y_label)
195+
196+
@staticmethod
197+
def remove_spines(axes: Axes, spines_to_remove: list[str]) -> None:
198+
for spine in spines_to_remove:
199+
axes.spines[spine].set_visible(False)

0 commit comments

Comments
 (0)