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 1540f9c

Browse filesBrowse files
authored
Merge pull request #74 from kushalkolar/docstrings
adding some more docstrings
2 parents bca7620 + 7149752 commit 1540f9c
Copy full SHA for 1540f9c

File tree

Expand file treeCollapse file tree

6 files changed

+208
-24
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+208
-24
lines changed

‎fastplotlib/graphics/heatmap.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/heatmap.py
+26-1Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,32 @@ def __init__(
5151
*args,
5252
**kwargs
5353
):
54-
super().__init__(data, vmin, vmax, cmap)
54+
"""
55+
Create a Heatmap Graphic
56+
57+
Parameters
58+
----------
59+
data: array-like, must be 2-dimensional
60+
| array-like, usually numpy.ndarray, must support ``memoryview()``
61+
| Tensorflow Tensors also work _I think_, but not thoroughly tested
62+
63+
vmin: int, optional
64+
minimum value for color scaling, calculated from data if not provided
65+
66+
vmax: int, optional
67+
maximum value for color scaling, calculated from data if not provided
68+
69+
cmap: str, optional
70+
colormap to use to display the image data, default is ``"plasma"``
71+
72+
selection_options
73+
74+
args:
75+
additional arguments passed to Graphic
76+
kwargs:
77+
additional keyword arguments passed to Graphic
78+
"""
79+
super().__init__(data, vmin, vmax, cmap, *args, **kwargs)
5580

5681
self.selection_options = SelectionOptions()
5782
self.selection_options.callbacks = list()

‎fastplotlib/graphics/histogram.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/histogram.py
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ def __init__(
2525
draw_bin_width_scale: float = 1.0,
2626
**kwargs
2727
):
28+
"""
29+
Create a Histogram Graphic
30+
31+
Parameters
32+
----------
33+
data: np.ndarray or None, optional
34+
data to create a histogram from, can be ``None`` if pre-computed values are provided to ``pre_computed``
35+
36+
bins: int or str, default is "auto", optional
37+
this is directly just passed to ``numpy.histogram``
38+
39+
pre_computed: dict in the form {"hist": vals, "bin_edges" : vals}, optional
40+
pre-computed histogram values
41+
42+
colors: np.ndarray, optional
43+
44+
draw_scale_factor: float, default ``100.0``, optional
45+
scale the drawing of the entire Graphic
46+
47+
draw_bin_width_scale: float, default ``1.0``
48+
scale the drawing of the bin widths
49+
50+
kwargs
51+
passed to Graphic
52+
"""
2853

2954
if pre_computed is None:
3055
self.hist, self.bin_edges = np.histogram(data, bins)

‎fastplotlib/graphics/image.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/image.py
+44-3Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Tuple
1+
from typing import *
22

33
import numpy as np
44
import pygfx
@@ -10,13 +10,55 @@
1010
class ImageGraphic(Graphic):
1111
def __init__(
1212
self,
13-
data: np.ndarray,
13+
data: Any,
1414
vmin: int = None,
1515
vmax: int = None,
1616
cmap: str = 'plasma',
1717
*args,
1818
**kwargs
1919
):
20+
"""
21+
Create an Image Graphic
22+
23+
Parameters
24+
----------
25+
data: array-like, must be 2-dimensional
26+
| array-like, usually numpy.ndarray, must support ``memoryview()``
27+
| Tensorflow Tensors also work _I think_, but not thoroughly tested
28+
29+
vmin: int, optional
30+
minimum value for color scaling, calculated from data if not provided
31+
32+
vmax: int, optional
33+
maximum value for color scaling, calculated from data if not provided
34+
35+
cmap: str, optional
36+
colormap to use to display the image data, default is ``"plasma"``
37+
args:
38+
additional arguments passed to Graphic
39+
kwargs:
40+
additional keyword arguments passed to Graphic
41+
42+
Examples
43+
--------
44+
45+
.. code-block:: python
46+
47+
from fastplotlib import Plot
48+
49+
# create a `Plot` instance
50+
plot = Plot()
51+
52+
# make some random 2D image data
53+
data = np.random.rand(512, 512)
54+
55+
# plot the image data
56+
plot.add_image(data=data)
57+
58+
# show the plot
59+
plot.show()
60+
61+
"""
2062
if data.ndim != 2:
2163
raise ValueError("`data.ndim !=2`, you must pass only a 2D array to `data`")
2264

@@ -45,4 +87,3 @@ def update_data(self, data: np.ndarray):
4587
def update_cmap(self, cmap: str, alpha: float = 1.0):
4688
self.world_object.material.map = get_cmap_texture(name=cmap)
4789
self.world_object.geometry.grid.update_range((0, 0, 0), self.world_object.geometry.grid.size)
48-

‎fastplotlib/graphics/line.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/line.py
+35-1Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
1+
from typing import *
12
import numpy as np
23
import pygfx
34

45
from ._base import Graphic
56

67

78
class LineGraphic(Graphic):
8-
def __init__(self, data: np.ndarray, z_position: float = 0.0, size: float = 2.0, colors: np.ndarray = None, cmap: str = None, *args, **kwargs):
9+
def __init__(
10+
self,
11+
data: Any,
12+
z_position: float = 0.0,
13+
size: float = 2.0,
14+
colors: np.ndarray = None,
15+
cmap: str = None,
16+
*args,
17+
**kwargs
18+
):
19+
"""
20+
Create a line Graphic, 2d or 3d
21+
22+
Parameters
23+
----------
24+
data: array-like
25+
Line data to plot, 2D must be of shape [n_points, 2], 3D must be of shape [n_points, 3]
26+
27+
z_position: float, optional
28+
z-axis position for placing the graphic
29+
30+
size: float, optional
31+
thickness of the line
32+
33+
colors:
34+
35+
cmap: str, optional
36+
apply a colormap to the line instead of assigning colors manually
37+
38+
args
39+
passed to Graphic
40+
kwargs
41+
passed to Graphic
42+
"""
943
super(LineGraphic, self).__init__(data, colors=colors, cmap=cmap, *args, **kwargs)
1044

1145
self.fix_data()

‎fastplotlib/layouts/_gridplot.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_gridplot.py
+18-19Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,33 @@ def __init__(
3131
**kwargs
3232
):
3333
"""
34+
A grid of subplots.
35+
3436
Parameters
3537
----------
36-
shape:
37-
nrows, ncols
38-
39-
cameras: Union[np.ndarray, str]
40-
One of ``"2d"`` or ``"3d"`` indicating 2D or 3D plots
41-
42-
OR
38+
shape: tuple of int
39+
(n_rows, n_cols)
4340
44-
Array of ``2d`` and/or ``3d`` that specifies camera type for each subplot:
45-
``2d``: ``pygfx.OrthographicCamera``
46-
``3d``: ``pygfx.PerspectiveCamera``
41+
cameras: np.ndarray or str, optional
42+
| One of ``"2d"`` or ``"3d"`` indicating 2D or 3D cameras for all subplots
4743
48-
controllers: np.ndarray
49-
numpy array of same shape as ``grid_shape`` that defines the controllers
50-
Example:
51-
unique controllers for a 2x2 gridplot: np.array([[0, 1], [2, 3]])
52-
same controllers for first 2 plots: np.array([[0, 0, 1], [2, 3, 4]])
44+
| OR
5345
54-
If `None` a unique controller is created for each subplot
46+
| Array of ``2d`` and/or ``3d`` that specifies the camera type for each subplot:
5547
56-
If "sync" all the subplots use the same controller
48+
controllers: np.ndarray or str, optional
49+
| If `None` a unique controller is created for each subplot
50+
| If "sync" all the subplots use the same controller
51+
| If ``numpy.array``, its shape must be the same as ``grid_shape``.
52+
This allows custom assignment of controllers
53+
| Example:
54+
| unique controllers for a 2x2 gridplot: np.array([[0, 1], [2, 3]])
55+
| same controllers for first 2 plots and last 2 plots: np.array([[0, 0, 1], [2, 3, 3]])
5756
58-
canvas: WgpuCanvas
57+
canvas: WgpuCanvas, optional
5958
Canvas for drawing
6059
61-
renderer: pygfx.Renderer
60+
renderer: pygfx.Renderer, optional
6261
pygfx renderer instance
6362
"""
6463
self.shape = shape

‎fastplotlib/plot.py

Copy file name to clipboardExpand all lines: fastplotlib/plot.py
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,66 @@ def __init__(
1313
controller: Union[pygfx.PanZoomController, pygfx.OrbitOrthoController] = None,
1414
**kwargs
1515
):
16+
"""
17+
Simple Plot object.
18+
19+
Parameters
20+
----------
21+
canvas: WgpuCanvas, optional
22+
Canvas for drawing
23+
24+
renderer: pygfx.Renderer, optional
25+
pygfx renderer instance
26+
27+
camera:str, optional
28+
| One of ``"2d"`` or ``"3d"`` indicating 2D or 3D camera
29+
30+
controller: None, PanZoomController or OrbitOrthoController, optional
31+
Usually ``None``, you can pass an existing controller from another
32+
``Plot`` or ``Subplot`` within a ``GridPlot`` to synchronize them.
33+
34+
kwargs
35+
passed to Subplot, for example ``name``
36+
37+
Examples
38+
--------
39+
40+
Simple example
41+
42+
.. code-block:: python
43+
44+
from fastplotlib import Plot
45+
46+
# create a `Plot` instance
47+
plot1 = Plot()
48+
49+
# make some random 2D image data
50+
data = np.random.rand(512, 512)
51+
52+
# plot the image data
53+
plot1.add_image(data=data)
54+
55+
# show the plot
56+
plot1.show()
57+
58+
Sharing controllers, start from the previous example and create a new jupyter cell
59+
60+
.. code-block:: python
61+
62+
# use the controller from the previous plot
63+
# this will sync the pan & zoom controller
64+
plot2 = Plot(controller=plot1.controller)
65+
66+
# make some random 2D image data
67+
data = np.random.rand(512, 512)
68+
69+
# plot the image data
70+
plot2.add_image(data=data)
71+
72+
# show the plot
73+
plot2.show()
74+
75+
"""
1676
super(Plot, self).__init__(
1777
position=(0, 0),
1878
parent_dims=(1, 1),

0 commit comments

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