def test_axis_ticks(limits, n_ticks, expected_ticks): """Test axis ticks generation""" axis = Axis(display_length=80) axis.limits = limits axis.nticks = n_ticks np.testing.assert_array_equal(axis.ticks, expected_ticks)
def test_axis_datetime_ticks(limits, n_ticks, expected_labels): axis = Axis(display_length=79) axis.nticks = n_ticks axis.fit(np.array(limits)) ticklabels = axis.ticklabels assert list(ticklabels) == list(expected_labels)
def test_axis_ticklabels_len_error(ticks, labels): """Test error raising when tick labels do not match ticks""" axis = Axis() axis.ticks = ticks with pytest.raises(ValueError): axis.ticklabels = labels
def test_axis_transform(x, expected_display_x): """Test axis transform from plot to display coordinates""" axis = Axis(display_length=80) axis.limits = (0, 100) display_x = axis.fit_transform(x) np.testing.assert_array_equal(display_x, expected_display_x)
def test_axis_display_ticks(limits, ticks, expected_tick_labels): """Test axis ticks generation""" axis = Axis(display_length=80) axis.limits = limits axis.ticks = ticks tick_labels = list(axis.generate_display_ticks()) assert tick_labels == expected_tick_labels
def test_axis_ticks_set_updates_ticklabels(): axis = Axis() axis.limits = (0, 1) axis.ticks = (0.0, 0.3, 1.0) np.testing.assert_array_equal(axis.ticklabels, np.array([0.0, 0.3, 1.0])) axis.ticks = (0.0, 0.2) np.testing.assert_array_equal(axis.ticklabels, np.array([0.0, 0.2]))
def __init__( self, figsize: Optional[Tuple[int]] = None, xlim: Optional[array_like] = None, xticks: Optional[array_like] = None, xticklabels: Optional[array_like] = None, xlabel: Optional[str] = None, ylim: Optional[array_like] = None, yticks: Optional[array_like] = None, yticklabels: Optional[array_like] = None, ylabel: Optional[str] = None, title: Optional[str] = None, **kwargs ) -> None: """Instantiate a new figure Parameters ---------- figsize : a tuple (width, height) in ascii characters, optional Size of the figure. xlim : 2-tuple/list, optional Set the x limits. xticks : Optional[array_like], optional [description], by default None xticklabels : Optional[array_like], optional [description], by default None xlabel : Optional[str], optional Name to use for the xlabel on x-axis. ylim : 2-tuple/list, optional Set the y limits. yticks : Optional[array_like], optional [description], by default None yticklabels : Optional[array_like], optional [description], by default None ylabel : Optional[str], optional Name to use for the ylabel on y-axis. title : Optional[str], optional The title of the figure. """ self.figsize = figsize or config["figsize"] self.x_axis = Axis( display_length=self.figsize[0], limits=xlim, ticks=xticks, ticklabels=xticklabels, label=xlabel, ) self.y_axis = Axis( display_length=self.figsize[1], limits=ylim, ticks=yticks, ticklabels=yticklabels, label=ylabel, ) self.title = title self.clear()
def test_axis_limit_set_updates_ticks(): axis = Axis(display_length=80) axis.limits = (0, 300) np.testing.assert_array_equal(axis.ticks, np.array([0, 50, 100, 150, 200, 250, 300])) axis.limits = (50, 80) np.testing.assert_array_equal(axis.ticks, np.array([50, 55, 60, 65, 70, 75, 80]))
def test_axis_property_setting(axis_property, value, expected_value): axis = Axis() axis = axis.fit((0, 1)) axis.nticks = 3 setattr(axis, axis_property, value) set_value = getattr(axis, axis_property) if isinstance(expected_value, np.ndarray): np.testing.assert_array_equal(set_value, expected_value) else: assert set_value == expected_value
def test_axis_nticks_set_updates_ticks(): axis = Axis() axis.limits = (0, 1) axis.nticks = 2 np.testing.assert_array_equal(axis.ticks, np.array([0.0, 1.0])) axis.nticks = 3 np.testing.assert_array_equal(axis.ticks, np.array([0.0, 0.5, 1.0])) axis.nticks = 5 np.testing.assert_array_equal(axis.ticks, np.array([0.0, 0.25, 0.5, 0.75, 1.0]))
"lines,ref_lines,expecte_padded_lines", [ (["a", "b"], ["a", "b", "c"], ["", "a", "b"]), (None, ["a", "b", "c"], ["", "", ""]), ], ) def test_pad_lines(lines, ref_lines, expecte_padded_lines): padded_lines = _pad_lines(lines, ref_lines) assert padded_lines == expecte_padded_lines @pytest.mark.parametrize( "axis,expected_axis_lines", [ ( Axis(display_length=51, label="my_fun_label", limits=(0, 1)), [ "└┬---------┬---------┬---------┬---------┬---------┬\n", " 0.0 0.2 0.4 0.6 0.8 1.0\n", " my_fun_label", ], ), ( Axis(display_length=51, label="my_fun_label", limits=(0, 0.01)), [ "└┬---------┬---------┬---------┬---------┬---------┬\n", " 0.0 0.002 0.004 0.006 0.008 0.01\n", " my_fun_label", ], ), ],
def test_axis_auto_limits(x, expected_limits): """Check whether automatically determined limits are sensible""" axis = Axis(display_length=81) axis = axis.fit(x) np.testing.assert_array_equal(axis.limits, expected_limits)
def test_axis_ticks_before_fit_error(): axis = Axis() with pytest.raises(ValueError): axis.ticks
(np.array([0, 25]), np.array([0, 20])), ], ) def test_axis_transform(x, expected_display_x): """Test axis transform from plot to display coordinates""" axis = Axis(display_length=80) axis.limits = (0, 100) display_x = axis.fit_transform(x) np.testing.assert_array_equal(display_x, expected_display_x) @pytest.mark.parametrize( "axis, expected_n_ticks", [ (Axis(display_length=20), 4), (Axis(display_length=30), 5), (Axis(display_length=50), 5), (Axis(display_length=80), 7), ], ) def test_axis_auto_nticks(axis, expected_n_ticks): """Auto n_ticks test""" n_ticks = axis._auto_nticks() assert n_ticks == expected_n_ticks @pytest.mark.parametrize( # fmt: off "limits, n_ticks, expected_ticks", [