def test_doc_00(self): # Create the figure. This automatically sets itself as the current # working figure. The qapp is created automatically if one doesn't # already exist. vpl.QtFigure("Exciting Window Title") # Everything from here on should be exactly the same as normal. vpl.quick_test_plot()
def test_conversions(): vpl.quick_test_plot() arr = vpl.screenshot_fig() vpl.close() image_data = vpl.image_io.vtkimagedata_from_array(arr) arr2 = vpl.image_io.vtkimagedata_to_array(image_data) assert np.array_equal(arr, arr2)
def test_trim_image(): fig = vpl.figure() # Shouldn't do anything if the figure is empty. assert vpl.screenshot_fig(trim_pad_width=.05).shape[:2] == fig.render_size vpl.quick_test_plot() arr = vpl.screenshot_fig() vpl.close() trimmed = vpl.image_io.trim_image(arr, fig.background_color, 10) background_color = np.asarray(fig.background_color) * 255 # Check that no non-background coloured pixels have been lost. assert (arr != background_color).any(-1).sum() \ == (trimmed != background_color).any(-1).sum() return trimmed
def test_qfigure2(self): fig = vpl.QtFigure2("a qt widget figure") self.assertIs(fig, vpl.gcf()) vpl.scatter(np.arange(9).reshape((3, 3)).T) vpl.quick_test_plot() fig.add_all() fig.show(block=False) fig.qapp.processEvents() for i in fig.view_buttons.buttons: i.released.emit() fig.qapp.processEvents() time.sleep(.1) fig.screenshot_button.released.emit() fig.show_plot_table_button.released.emit() fig.show()
def test_qfigure2(): fig = vpl.QtFigure2("a QWidget figure") fig.setWindowTitle(fig.window_name) assert fig is vpl.gcf() plot = vpl.scatter(np.arange(9).reshape((3, 3)).T)[0] vpl.quick_test_plot() fig.add_all() fig.show(block=False) fig.qapp.processEvents() for i in fig.view_buttons.buttons: i.released.emit() fig.qapp.processEvents() time.sleep(.1) if not VTKPLOTLIB_WINDOWLESS_TEST: fig.screenshot_button.released.emit() fig.show_plot_table_button.released.emit() fig.show(block=False) for plot in fig.plot_table.rows: fig.plot_table.rows[plot].text.released.emit() fig.qapp.processEvents() assert not plot.visible assert np.allclose(vpl.screenshot_fig(fig=fig), np.array(255) * fig.background_color, atol=1.) for plot in fig.plot_table.rows: fig.plot_table.rows[plot].text.released.emit() fig.qapp.processEvents() assert plot.visible fig.plot_table.close()
def test_add_remove(self): fig = vpl.figure() plots = vpl.quick_test_plot(None) fig += plots fig.show(False) fig -= plots for i in plots: fig += i fig.update() time.sleep(.05) for i in plots: fig -= i fig.update() time.sleep(.05) vpl.close(fig)
def _mouse_move_cb(self, invoker, name): if self._click_location: self.pick.update() if self._clicks_are_equal(self._click_location, self.pick.point_2D): return self._click_location = None # Only calling the super event with the mouse button down (which rotates # the model for left click) when we are sure that this click is not # meant to place a marker reduces the slight jolt when you click on with # a sensitive mouse. Move the lines below to the top of this method to # see what I mean. if self._super_on_mouse_move: call_super_callback() if __name__ == "__main__": import vtkplotlib as vpl fig = vpl.QtFigure2() style = fig.style balls = vpl.quick_test_plot() rabbit = vpl.mesh_plot(vpl.data.get_rabbit_stl()) rabbit.vertices -= [i.mean() for i in vpl.unzip_axes(rabbit.vertices)] rabbit.vertices /= 5 text = vpl.text("text") vpl.show()
def test_doc_13(self): vpl.quick_test_plot()
def test_quick_test_plot(): import vtkplotlib as vpl vpl.quick_test_plot()