forked from fastplotlib/fastplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
60 lines (48 loc) · 1.68 KB
/
Copy pathplot.py
File metadata and controls
60 lines (48 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pygfx
from pygfx.linalg import Vector3
from wgpu.gui.auto import WgpuCanvas
from .subplot import Subplot
from .graphics import *
class Plot(Subplot):
def __init__(
self,
canvas: WgpuCanvas = None,
renderer: pygfx.Renderer = None,
camera: str = '2d',
controller: Union[pygfx.PanZoomController, pygfx.OrbitOrthoController] = None
):
super(Plot, self).__init__(
position=(0, 0),
parent_dims=(1, 1),
canvas=canvas,
renderer=renderer,
camera=camera,
controller=controller
)
def image(self, *args, **kwargs):
graphic = Image(*args, **kwargs)
self.scene.add(graphic.world_object)
dims = graphic.data.shape
zero_pos = Vector3(dims[0] / 2, dims[1] / 2, self.camera.position.z)
delta = zero_pos.clone().sub(self.camera.position)
zoom_level = 1 / np.mean(dims)
if self.controller.zoom_value != zoom_level:
self.controller.zoom(zoom_level)
self.controller.pan(delta)
return graphic
def line(self, *args, **kwargs):
graphic = Line(*args, **kwargs)
self.scene.add(graphic.world_object)
return graphic
def scatter(self, *args, **kwargs):
graphic = Scatter(*args, **kwargs)
self.scene.add(graphic.world_object)
self.camera.show_object(graphic.world_object)
return graphic
def animate(self):
super(Plot, self).animate(canvas_dims=None)
self.renderer.flush()
self.canvas.request_draw()
def show(self):
self.canvas.request_draw(self.animate)
return self.canvas