Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a59b2c

Browse filesBrowse files
authored
Merge branch 'master' into heatmap-graphic-2
2 parents 5fa80a7 + d70f4af commit 3a59b2c
Copy full SHA for 3a59b2c

File tree

Expand file treeCollapse file tree

7 files changed

+81
-15
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+81
-15
lines changed

‎fastplotlib/defaults.py

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
import pygfx
2+
from typing import *
23

34
camera_types = {
45
'2d': pygfx.OrthographicCamera,
56
'3d': pygfx.PerspectiveCamera,
67
}
8+
79
controller_types = {
810
'2d': pygfx.PanZoomController,
911
'3d': pygfx.OrbitOrthoController,
1012
pygfx.OrthographicCamera: pygfx.PanZoomController,
1113
pygfx.PerspectiveCamera: pygfx.OrbitOrthoController,
1214
}
15+
16+
17+
def create_camera(camera_type: str, big_camera: bool = False) -> Union[pygfx.OrthographicCamera, pygfx.PerspectiveCamera]:
18+
camera_type = camera_type.split("-")
19+
20+
# kinda messy but works for now
21+
if len(camera_type) > 1:
22+
if camera_type[1] == "big":
23+
big_camera = True
24+
25+
camera_type = camera_type[0]
26+
else:
27+
camera_type = camera_type[0]
28+
29+
cls = camera_types[camera_type]
30+
31+
if cls is pygfx.OrthographicCamera:
32+
if big_camera:
33+
return cls(1024, 1024, -8192, 8192)
34+
else:
35+
return cls(1024, 1024)
36+
37+
else:
38+
return cls()
39+
40+
41+
def create_controller(controller_type: str):
42+
controller_type = controller_type.split("-")[0]
43+
44+
return controller_types[controller_type]()

‎fastplotlib/graphics/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_base.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ def children(self) -> pygfx.WorldObject:
6161

6262
def update_data(self, data: Any):
6363
pass
64+
65+
def __repr__(self):
66+
if self.name is not None:
67+
return f"'{self.name}' fastplotlib.{self.__class__.__name__} @ {hex(id(self))}"
68+
else:
69+
return f"fastplotlib.{self.__class__.__name__} @ {hex(id(self))}"
70+

‎fastplotlib/graphics/histogram.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/histogram.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def __init__(
2222
pre_computed: Dict[str, np.ndarray] = None,
2323
colors: np.ndarray = None,
2424
draw_scale_factor: float = 100.0,
25-
draw_bin_width_scale: float = 1.0
25+
draw_bin_width_scale: float = 1.0,
26+
**kwargs
2627
):
2728

2829
if pre_computed is None:
@@ -56,7 +57,7 @@ def __init__(
5657

5758
data = np.vstack([x_positions_bins, self.hist])
5859

59-
super(Histogram, self).__init__(data=data, colors=colors, colors_length=n_bins)
60+
super(Histogram, self).__init__(data=data, colors=colors, colors_length=n_bins, **kwargs)
6061

6162
self.world_object: pygfx.Group = pygfx.Group()
6263

@@ -73,3 +74,4 @@ def __init__(
7374
hist_bin_graphic.frequency = y_val
7475

7576
self.world_object.add(hist_bin_graphic)
77+

‎fastplotlib/graphics/image.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/image.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ def update_data(self, data: np.ndarray):
4444

4545
def update_cmap(self, cmap: str, alpha: float = 1.0):
4646
self.world_object.material.map = get_cmap_texture(name=cmap)
47+

‎fastplotlib/layouts.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts.py
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from itertools import product
22
import numpy as np
33
import pygfx
4-
from .defaults import camera_types, controller_types
4+
from .defaults import create_controller
55
from .subplot import Subplot
66
from typing import *
77
from wgpu.gui.auto import WgpuCanvas
8+
from ipywidgets import GridspecLayout, Textarea
9+
from tabulate import tabulate
810

911

1012
class GridPlot:
@@ -51,7 +53,7 @@ def __init__(
5153
self.shape = shape
5254

5355
if type(cameras) is str:
54-
if cameras not in ["2d", "3d"]:
56+
if cameras not in ["2d", "2d-big", "3d", "3d-big"]:
5557
raise ValueError("If passing a str, `views` must be one of `2d` or `3d`")
5658
# create the array representing the views for each subplot in the grid
5759
cameras = np.array([cameras] * self.shape[0] * self.shape[1]).reshape(self.shape)
@@ -103,7 +105,7 @@ def __init__(
103105
if cam.size > 1:
104106
raise ValueError(f"Controller id: {controller} has been assigned to multiple different camera types")
105107

106-
self._controllers[controllers == controller] = controller_types[cam[0]]()
108+
self._controllers[controllers == controller] = create_controller(cam[0])
107109

108110
for i, j in self._get_iterator():
109111
position = (i, j)
@@ -168,3 +170,9 @@ def __iter__(self):
168170
def __next__(self) -> Subplot:
169171
pos = self._current_iter.__next__()
170172
return self._subplots[pos]
173+
174+
def __repr__(self):
175+
return f"fastplotlib.{self.__class__.__name__} @ {hex(id(self))}\n"
176+
177+
178+

‎fastplotlib/plot.py

Copy file name to clipboardExpand all lines: fastplotlib/plot.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ def __init__(
1313
canvas: WgpuCanvas = None,
1414
renderer: pygfx.Renderer = None,
1515
camera: str = '2d',
16-
controller: Union[pygfx.PanZoomController, pygfx.OrbitOrthoController] = None
16+
controller: Union[pygfx.PanZoomController, pygfx.OrbitOrthoController] = None,
17+
**kwargs
1718
):
1819
super(Plot, self).__init__(
1920
position=(0, 0),
2021
parent_dims=(1, 1),
2122
canvas=canvas,
2223
renderer=renderer,
2324
camera=camera,
24-
controller=controller
25+
controller=controller,
26+
**kwargs
2527
)
2628

2729
for graphic_cls_name in graphics.__all__:

‎fastplotlib/subplot.py

Copy file name to clipboardExpand all lines: fastplotlib/subplot.py
+22-8Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pygfx
22
from pygfx import Scene, OrthographicCamera, PerspectiveCamera, PanZoomController, Viewport, AxesHelper, GridHelper
3-
from .defaults import camera_types, controller_types
43
from .graphics import Heatmap
4+
from .defaults import create_camera, create_controller
55
from typing import *
66
from wgpu.gui.auto import WgpuCanvas
77
from warnings import warn
88
from math import copysign
9+
from textwrap import indent
910

1011

1112
class Subplot:
@@ -46,10 +47,10 @@ def __init__(
4647

4748
self.nrows, self.ncols = parent_dims
4849

49-
self.camera: Union[pygfx.OrthographicCamera, pygfx.PerspectiveCamera] = camera_types[camera]()
50+
self.camera: Union[pygfx.OrthographicCamera, pygfx.PerspectiveCamera] = create_camera(camera)
5051

5152
if controller is None:
52-
controller = controller_types[camera]()
53+
controller = create_controller(camera)
5354
self.controller: Union[pygfx.PanZoomController, pygfx.OrbitOrthoController] = controller
5455

5556
# might be better as an attribute of GridPlot
@@ -96,13 +97,14 @@ def add_animations(self, funcs: List[callable]):
9697
self._animate_funcs += funcs
9798

9899
def add_graphic(self, graphic, center: bool = True):
99-
graphic_names = list()
100+
if graphic.name is not None: # skip for those that have no name
101+
graphic_names = list()
100102

101-
for g in self._graphics:
102-
graphic_names.append(g.name)
103+
for g in self._graphics:
104+
graphic_names.append(g.name)
103105

104-
if graphic.name in graphic_names:
105-
raise ValueError(f"graphics must have unique names, current graphic names are:\n {graphic_names}")
106+
if graphic.name in graphic_names:
107+
raise ValueError(f"graphics must have unique names, current graphic names are:\n {graphic_names}")
106108

107109
self._graphics.append(graphic)
108110
self.scene.add(graphic.world_object)
@@ -175,3 +177,15 @@ def __getitem__(self, name: str):
175177
for g in self._graphics:
176178
graphic_names.append(g.name)
177179
raise IndexError(f"no graphic of given name, the current graphics are:\n {graphic_names}")
180+
181+
def __repr__(self):
182+
newline = "\n "
183+
if self.name is not None:
184+
return f"'{self.name}' fastplotlib.{self.__class__.__name__} @ {hex(id(self))}\n" \
185+
f"Graphics: \n " \
186+
f"{newline.join(graphic.__repr__() for graphic in self.get_graphics())}"
187+
else:
188+
return f"fastplotlib.{self.__class__.__name__} @ {hex(id(self))} \n" \
189+
f"Graphics: \n " \
190+
f"{newline.join(graphic.__repr__() for graphic in self.get_graphics())}"
191+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.