def test_point_plot(): x = np.random.normal(size=(100, 2)) a = hdviz.create_plotter(2) a.add_pointset(x) b = a.plot(title="Hei", square=False) assert str(b)[0:11] == "AxesSubplot" a.clear_data()
def test_mixed_plot(): l1 = create_3d_spiral(1.0) l2 = create_3d_spiral(1.5) x = np.stack((l1, l2)) a = hdviz.create_plotter(3) a.add_lineset(x, label="lines", alpha=0.3) x2 = np.random.normal(size=(10, 3)) a.add_pointset(x2, marker="x", color="red") assert a.num_pointsets() == 1 assert a.num_linesets() == 1
def test_plot_3d(): x = np.random.normal(size=(100, 3)) a = hdviz.create_plotter(3, no_3d=True) a.add_pointset(x, label="points", alpha=0.7) assert a.num_pointsets() == 1 ax = a.plot(panelsize=2, square=True) assert ax.shape == (1, 3) with pytest.raises(RuntimeError): a.plot(figsize=(7, 10)) a.clear_data()
def test_quiver_plot(): a = hdviz.create_plotter(3) x = np.random.normal(size=(10, 3)) a.add_pointset(x, marker="x", color="red") u = a.create_grid_around_points(square=False, M=8) v1 = np.sin(u[:, 0]) v2 = np.cos(u[:, 1] + 0.1 * u[:, 0]) v3 = 0.1 * u[:, 2] v = np.vstack((v1, v2, v3)).T a.add_quiverset(u, v, color="blue", alpha=0.5) assert a.num_quiversets() == 1
def test_point_plot(): x = np.random.normal(size=(100, 3)) a = hdviz.create_plotter(3) a.add_pointset(x, label="example_data", alpha=0.3) x2 = np.random.normal(size=(10, 3)) a.add_pointset(x2, label="example_other", marker="x", color="red") x = np.random.normal(size=(30, 3)) a.add_pointset(x) assert a.num_pointsets() == 3 b = a.plot(title="Hei", square=True) assert str(b)[0:13] == "Axes3DSubplot" a.clear_data()
def test_adding_pointsets(): a = hdviz.create_plotter(3) x = 1.5 + 0.1 * np.random.normal(size=(100, 3)) a.add_pointset(x, label="first group", marker="x") x = np.random.normal(size=(100, 3)) labels = 10 * np.ones(100, dtype=int) labels[0:99] = np.random.choice(3, size=99) colors = dict(zip([0, 1, 2, 10], ["pink", "red", "orange", "black"])) a.add_pointsets(x, labels, label_name_prefix="additional", label_colors=colors, alpha=0.5) assert a.num_pointsets() == 5
def test_plot_5d(): x = np.random.normal(size=(100, 5)) a = hdviz.create_plotter(5) a.add_pointset(x, label="points", alpha=0.7, color="pink") t = -2.0 + 4.0 * np.linspace(0, 1, 100) f1 = t f2 = 0.5 * np.sin(t) f3 = np.cos(4 * t) f4 = -0.3 * t * t f5 = 0.0 * t v = np.stack((f1, f2, f3, f4, f5)).T a.add_quiverset(x, v, color="black") ax = a.plot() assert ax.shape == (3, 4)
def test_plot_4d(): x = np.random.normal(size=(100, 4)) a = hdviz.create_plotter(4) a.add_pointset(x, label="points", alpha=0.7) t = -2.0 + 4.0 * np.linspace(0, 1, 100) y1 = t y2 = 0.5 * np.sin(t) y3 = np.cos(4 * t) y4 = -0.3 * t * t lin = np.stack((y1, y2, y3, y4)).T ls = np.stack((lin, lin + 0.5)) a.add_lineset(ls, color="red") ax = a.plot(panelsize=3) assert ax.shape == (2, 3)
def test_quiver_plot(): x1 = np.random.normal(loc=[-1, -1], size=(100, 2)) x2 = np.random.normal(loc=[-10, 3], size=(100, 2)) x3 = np.random.normal(loc=[3, 2], size=(100, 2)) a = hdviz.create_plotter(2) a.add_pointset(x1) a.add_pointset(x2) a.add_pointset(x3) u = a.create_grid_around_points(square=False) v1 = np.sin(u[:, 0]) v2 = np.cos(u[:, 1] + 0.1 * u[:, 0]) v = np.vstack((v1, v2)).T a.add_quiverset(u, v, color="red") b = a.plot(square=True) assert str(b)[0:11] == "AxesSubplot"
def test_line_plot(): x = np.random.normal(size=(10, 100, 3)) a = hdviz.create_plotter(3) a.add_lineset(x, label="lines", alpha=0.8) assert a.num_pointsets() == 0 assert a.num_linesets() == 1