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
105 lines (77 loc) · 2.6 KB
/
Copy pathplot.py
File metadata and controls
105 lines (77 loc) · 2.6 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from typing import *
import pygfx
from wgpu.gui.auto import WgpuCanvas
from .layouts._subplot import Subplot
class Plot(Subplot):
def __init__(
self,
canvas: WgpuCanvas = None,
renderer: pygfx.Renderer = None,
camera: str = '2d',
controller: Union[pygfx.PanZoomController, pygfx.OrbitOrthoController] = None,
**kwargs
):
"""
Simple Plot object.
Parameters
----------
canvas: WgpuCanvas, optional
Canvas for drawing
renderer: pygfx.Renderer, optional
pygfx renderer instance
camera:str, optional
| One of ``"2d"`` or ``"3d"`` indicating 2D or 3D camera
controller: None, PanZoomController or OrbitOrthoController, optional
Usually ``None``, you can pass an existing controller from another
``Plot`` or ``Subplot`` within a ``GridPlot`` to synchronize them.
kwargs
passed to Subplot, for example ``name``
Examples
--------
Simple example
.. code-block:: python
from fastplotlib import Plot
# create a `Plot` instance
plot1 = Plot()
# make some random 2D image data
data = np.random.rand(512, 512)
# plot the image data
plot1.add_image(data=data)
# show the plot
plot1.show()
Sharing controllers, start from the previous example and create a new jupyter cell
.. code-block:: python
# use the controller from the previous plot
# this will sync the pan & zoom controller
plot2 = Plot(controller=plot1.controller)
# make some random 2D image data
data = np.random.rand(512, 512)
# plot the image data
plot2.add_image(data=data)
# show the plot
plot2.show()
"""
super(Plot, self).__init__(
position=(0, 0),
parent_dims=(1, 1),
canvas=canvas,
renderer=renderer,
camera=camera,
controller=controller,
**kwargs
)
def render(self):
super(Plot, self).render()
self.renderer.flush()
self.canvas.request_draw()
def show(self):
"""
begins the rendering event loop and returns the canvas
Returns
-------
WgpuCanvas
the canvas
"""
self.canvas.request_draw(self.render)
self.auto_scale(maintain_aspect=True, zoom=0.95)
return self.canvas