Skip to content
Snippets Groups Projects
Commit aa30ee60 authored by Phil Colebrooke's avatar Phil Colebrooke
Browse files

Re #28464 fix problems with 2d and 3d plots on same figure

parent f383fbfc
No related branches found
No related tags found
No related merge requests found
......@@ -101,10 +101,17 @@ class AxesTabWidgetPresenter:
def update_view(self):
"""Update the properties in the view from the selected axes"""
self.current_view_props.clear()
ax_props = self.get_selected_ax_properties()
plot_is_3d = "zlim" in ax_props
# Enable the z-axis option if the plot is 3D.
self.view.z_radio_button.setEnabled("zlim" in ax_props)
self.view.z_radio_button.setEnabled(plot_is_3d)
# For tiled plots
if not plot_is_3d and self.view.z_radio_button.isChecked():
self.view.x_radio_button.click()
# Changing the axis scale doesn't work with 3D plots, this is a known matplotlib issue,
# so the scale option is disabled.
......@@ -137,4 +144,10 @@ class AxesTabWidgetPresenter:
self.view.set_label(self.current_view_props[f"{new_ax}label"])
self.view.set_scale(self.current_view_props[f"{new_ax}scale"])
else:
self.update_view()
ax_props = self.get_selected_ax_properties()
ax = self.view.get_axis()
lim = ax_props[f"{ax}lim"]
self.view.set_lower_limit(lim[0])
self.view.set_upper_limit(lim[1])
self.view.set_label(ax_props[f"{ax}label"])
self.view.set_scale(ax_props[f"{ax}scale"])
......@@ -53,24 +53,25 @@ class AxesTabWidgetPresenterTest(unittest.TestCase):
ax_mock = mock.MagicMock()
presenter = self._generate_presenter()
with mock.patch.object(presenter, 'get_selected_ax', lambda: ax_mock):
presenter.current_view_props = presenter.get_selected_ax_properties()
presenter.apply_properties()
# Mock properties object and view then test that the view's setters
# are called with the correct property values
ax_mock.set_title.assert_called_once_with(
presenter.current_view_props.title)
ax_mock.set_xlim.assert_called_once_with(
presenter.current_view_props.xlim)
ax_mock.set_xlabel.assert_called_once_with(
presenter.current_view_props.xlabel)
ax_mock.set_xscale.assert_called_once_with(
presenter.current_view_props.xscale)
ax_mock.set_ylim.assert_called_once_with(
presenter.current_view_props.ylim)
ax_mock.set_ylabel.assert_called_once_with(
presenter.current_view_props.ylabel)
ax_mock.set_yscale.assert_called_once_with(
presenter.current_view_props.yscale)
with mock.patch.object(presenter, 'update_view', lambda: None):
presenter.current_view_props = presenter.get_selected_ax_properties()
presenter.apply_properties()
# Mock properties object and view then test that the view's setters
# are called with the correct property values
ax_mock.set_title.assert_called_once_with(
presenter.current_view_props.title)
ax_mock.set_xlim.assert_called_once_with(
presenter.current_view_props.xlim)
ax_mock.set_xlabel.assert_called_once_with(
presenter.current_view_props.xlabel)
ax_mock.set_xscale.assert_called_once_with(
presenter.current_view_props.xscale)
ax_mock.set_ylim.assert_called_once_with(
presenter.current_view_props.ylim)
ax_mock.set_ylabel.assert_called_once_with(
presenter.current_view_props.ylabel)
ax_mock.set_yscale.assert_called_once_with(
presenter.current_view_props.yscale)
def test_get_axes_names_dict(self):
actual_dict = get_axes_names_dict(self.fig)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment