diff --git a/ndcube/mixins/plotting.py b/ndcube/mixins/plotting.py index 4554827d1..f25f76159 100644 --- a/ndcube/mixins/plotting.py +++ b/ndcube/mixins/plotting.py @@ -329,13 +329,7 @@ def _plot_3D_cube(self, plot_axis_indices=None, axes_coordinates=None, new_axes_coordinates, new_axes_units, default_labels = \ self._derive_axes_coordinates(axes_coordinates, axes_units) # If axis labels not set by user add to kwargs. - if "xlabel" not in kwargs: - kwargs["xlabel"] = default_labels[plot_axis_indices[0]] - if "ylabel" not in kwargs: - kwargs["ylabel"] = default_labels[plot_axis_indices[1]] ax = ImageAnimator(data, image_axes=plot_axis_indices, - unit_x_axis=new_axes_units[plot_axis_indices[0]], - unit_y_axis=new_axes_units[plot_axis_indices[1]], axis_ranges=new_axes_coordinates, **kwargs) return ax @@ -367,6 +361,12 @@ def _derive_axes_coordinates(self, axes_coordinates, axes_units): else: new_axis_unit = axes_units[i] new_axis_coordinate = new_axis_coordinate.to(new_axis_unit).value + elif isinstance(new_axis_coordinate[0], datetime.datetime): + axis_label_text = "{0}/sec since {1}".format( + axis_label_text, new_axis_coordinate[0]) + new_axis_coordinate = np.array([(t-new_axis_coordinate[0]).total_seconds() + for t in new_axis_coordinate]) + new_axis_unit = u.s else: if axes_units[i] is None: new_axis_unit = None diff --git a/ndcube/tests/test_plotting.py b/ndcube/tests/test_plotting.py index 86bfe8076..9a4dcea0d 100644 --- a/ndcube/tests/test_plotting.py +++ b/ndcube/tests/test_plotting.py @@ -43,7 +43,8 @@ ('bye', 2, u.Quantity(range(data.shape[2]), unit=u.m)), ('another time', 2, np.array( [datetime.datetime(2000, 1, 1)+datetime.timedelta(minutes=i) - for i in range(data.shape[2])])) + for i in range(data.shape[2])])), + ('array coord', 2, np.arange(100, 100+data.shape[2])) ]) cube_unit = NDCube( @@ -222,7 +223,7 @@ def test_cube_plot_2D(test_input, test_kwargs, expected_values): @pytest.mark.parametrize("test_input, test_kwargs, expected_error", [ - (cube[0], {"axes_coordinates": ["another time", None], "axes_units": [u.cm, None]}, TypeError), + (cube[0], {"axes_coordinates": ["array coord", None], "axes_units": [u.cm, None]}, TypeError), (cube[0], {"axes_coordinates": [np.arange(10, 10+cube[0].data.shape[1]), None], "axes_units": [u.cm, None]}, TypeError), (cube[0], {"data_unit": u.cm}, TypeError) @@ -231,6 +232,7 @@ def test_cube_plot_2D_errors(test_input, test_kwargs, expected_error): with pytest.raises(expected_error): output = test_input.plot(**test_kwargs) + @pytest.mark.parametrize("test_input, test_kwargs, expected_values", [ (cubem, {}, (cubem.data, [np.array([0., 2.]), [0, 3], [0, 4]], "", ""))