3.1.7. Option visualization¶
3.1.7.1. Description¶
Applications that enable visualize data anywhere in any stages through minimal calling. Helpful for data diagnosis,
position and orientation checking (specifically for medical images), making analysis and summary, as well as result
export. Running of this module requires pyqtgraph and one of compatible backends.
All object listed here have been integrated into the entry of info.vis.
configuration for plotting group data. |
|
default figure configuration container. |
|
generic visualization utility. |
|
interactive viewer for 3D image. |
3.1.7.2. Docstrings¶
- class GrpSettings¶
configuration for plotting group data. arguments vary among groups should to be listed as the identical size as the number of groups.
- Arguments:
- Parameters:
kwargs (dict) – initiate using keywords and values; no assignment for empty dict
{}as default- Variables:
~verbosity (bool) – show warning or not;
Falseas default- Returns:
figure configuration dict
- Return type:
- Raises:
TypeError – if
nameis not assigned properly
- Property:
- sub:
intrinsic number of groups for valid iteration.
- groups:
tuple composed of plot configuration for each group. prompt UserWarning if self adaption run due to length of list container does not match
self.subif~verbosityisTrue.
- Methods:
- update:
return a copy of self. can be updated from
kwargs
- Examples:
from info.vis import visualization as vis import pyqtgraph as pg import numpy as np # prepare data mvn, r_mu, r_sigma = (np.random.multivariate_normal, (lambda: np.random.randint(0, 10, 2)), (lambda: np.diag(np.random.random(2)))) groups = [mvn(mean=r_mu(), cov=r_sigma(), size=_).T for _ in [20, 40, 30]] x, y = np.array([v for v, _ in groups], dtype=object), np.array([v for _, v in groups], dtype=object) # assign plot configuration for 3 groups via GrpSettings: config = vis.GrpSettings(**{'pen': [pg.mkPen((0, 0, 0, 0)) for _ in range(3)], 'symbol': ['star', 'd', '+'], 'symbolSize': 15, 'symbolBrush': [_ for _ in 'rgb'], 'name': [f"type_{_+1}" for _ in range(3)]}) # scatter with customized configuration: app = vis.Canvas(fig_type='scatter', fig_configs=config, cvs_main='scatter figure', cvs_left_label='y_value', cvs_bottom_label='x_value', cvs_legend=True) app.view(data=(x, y))
The final plot will be:
Figure 3.1 canvas used for customized scatter plot¶
- See also:
- Logs:
Added in version 0.0.2.
– Created by Chen Zhang; Last updated on 01:34, 2025-09-06
- class FigConfigs¶
default figure configuration container. support types of line, scatter, histogram, beeswarm, box, and image. all properties in
FigConfigsareGrpSettingsinstances.- Arguments:
- Returns:
a basic figure configuration container
- Return type:
- Property:
- Line:
basic figure configuration for line plot.
- Scatter:
basic figure configuration for scatter plot.
- Histogram:
basic figure configuration for histogram plot.
- Beeswarm:
basic figure configuration for beeswarm plot.
- Box:
basic figure configuration for box plot.
- Radar:
basic figure configuration for radar plot.
- Image:
basic figure configurations for image viewer.
- Examples:
With
FigConfigs, it is handy to visualize data viaCanvas:from info.vis import visualization as vis import numpy as np # prepare data mvn, r_mu, r_sigma = (np.random.multivariate_normal, (lambda: np.random.randint(0, 10, 2)), (lambda: np.diag(np.random.random(2)))) groups = [mvn(mean=r_mu(), cov=r_sigma(), size=_).T for _ in [20, 40, 30]] x, y = np.array([v for v, _ in groups], dtype=object), np.array([v for _, v in groups], dtype=object) # scatter with default configuration: vis.Canvas.play(data=(x, y), fig_type='scatter', fig_configs=vis.FigConfigs.Scatter, cvs_main='scatter figure', cvs_left_label='y_value', cvs_bottom_label='x_value', cvs_legend=True)
Or customized some arguments based on
FigConfigs. For example, use the default histogram configuration withwidthas 0.2.vis.Canvas.play(data=y, fig_type='histogram', fig_configs=vis.FigConfigs.Histogram.update(width=0.2), cvs_main='histogram figure', cvs_left_label='y_value', cvs_bottom_label='x_value', cvs_legend=True)
- See also:
- Logs:
Added in version 0.0.2.
Changed in version 0.0.3: include default configuration for radar plot.
– Created by Chen Zhang; Last updated on 01:34, 2025-09-06
- class Canvas¶
generic visualization utility. making line, scatter, histogram, beeswarm, box, heatmap, radar, pie, contour figures for group and ungrouped data, or viewer for images.
- Arguments:
- Parameters:
data (Union[numpy.ndarray, tuple[numpy.ndarray, numpy.ndarray]]) – specified data during initialize a Canvas instance;
Noneas defaultfig_type (Literal[...]) – figure type for visualizer; should be option among
'line','scatter','histogram','beeswarm','box','heatmap','radar','pie','contour'and'image';'line'as defaultfig_configs (GrpSettings) – instance of GrpSettings; FigConfigs is the collection of default configurations for all figure types;
Noneas default will heuristically guess then configure fromfig_typecvs_main (str) – main title for application window;
'info'as defaultcvs_size (tuple[int, int]) – main window size;
Noneas default for applying(640, 480)on line, scatter, histogram, beeswarm, box plots or image viewer,(560, 560)on radar and pie plotscvs_background (str) – background color for canvas;
'w'as defaultcvs_grid (dict) – trigger to (un)enable grids of x and y in figure;
{'x': True, 'y': True}as defaultcvs_title (str) – title of figure;
Noneas defaultcvs_title_configs (dict) – configurations of figure title;
{'color': 'k', 'size': '15pt'}as defaultcvs_left_label (str) – text content for left label;
Noneas defaultcvs_bottom_label (str) – text content for bottom label;
Noneas defaultcvs_label_configs (dict) – configurations of left and bottom labels;
{'color': 'b', 'font-size': '13pt'}as defaultcvs_legend (bool) – trigger to (un)enable figure legend;
Falseas defaultcvs_axes (dict[str, bool]) – (un)display axes triggers;
{'left': True, 'top': False, 'right': False, 'bottom': True}as default
- Returns:
a visualization application
- Return type:
- Raises:
ValueError – invalid argument exists
- Methods:
- view:
show figure.
datacan be updated.
- save:
static method;
save_asto specify the file name for figure to be exported;figure.pngas default
- play:
static method; create a new canvas then show figure. all
**kwargsassignment supported.
- Examples:
Use
Canvasto build line plot:from info.vis import visualization as vis import numpy as np # prepare data mvn, r_mu, r_sigma = (np.random.multivariate_normal, (lambda: np.random.randint(0, 10, 2)), (lambda: np.diag(np.random.random(2)))) groups = [mvn(mean=r_mu(), cov=r_sigma(), size=_).T for _ in [20, 40, 30]] x, y = np.array([v for v, _ in groups], dtype=object), np.array([v for _, v in groups], dtype=object) vis.Canvas.play(data=y, fig_type='line', cvs_main='line figure', cvs_left_label='y_value', cvs_legend=True)
Figure 3.2 canvas used for line plot¶
And for scatter plot:
vis.Canvas.play(data=(x, y), fig_type='scatter', cvs_main='scatter figure', cvs_left_label='y_value', cvs_bottom_label='x_value', cvs_legend=True)
Figure 3.3 canvas used for scatter plot¶
And also for histogram plot:
vis.Canvas.play(data=y, fig_type='histogram', fig_configs=vis.FigConfigs.Histogram.update(width=0.2), cvs_main='histogram figure', cvs_left_label='y_value', cvs_bottom_label='x_value', cvs_legend=True)
Figure 3.4 canvas used for histogram plot¶
Also support for beeswarm plot:
vis.Canvas.play(data=y, fig_type='beeswarm', cvs_main='beeswarm figure', cvs_left_label='y_value', cvs_legend=True)
Figure 3.5 canvas used for beeswarm plot¶
For making box plot:
vis.Canvas.play(data=y, fig_type='box', cvs_main='box figure', cvs_left_label='y_value', cvs_legend=True)
Figure 3.6 canvas used for box plot¶
For making heatmap plot:
vec, mat = np.random.random(10), np.random.random((10, 4)) config1 = vis.FigConfigs.Heatmap.update(tags=np.array([f"V{_+1}" for _ in range(10)])) config2 = vis.FigConfigs.Heatmap.update(tags=np.array([f"S{_+1}" for _ in range(10)])) vis.Canvas.play(data=vec, fig_type='heatmap', fig_configs=config1, cvs_main='heatmap figure 1') vis.Canvas.play(data=mat, fig_type='heatmap', fig_configs=config2, cvs_main='heatmap figure 2')
Figure 3.7 canvas used for heatmap plot¶
For radar plot:
# generic radar plot vecs = np.array([np.random.randint(5, 10, 5) + np.random.random(5) for _ in range(3)]) vis.Canvas.play(data=vecs, fig_type='radar', cvs_main='radar figure', cvs_legend=True) # or be more customized import pyqtgraph as pg rescale_vecs, rescale_params = vis.rescale_radar(data=vecs, scale_base=2.3) cus_pen = pg.mkPen(color="#6a6da9", style=pg.QtGui.Qt.PenStyle.DashLine) vis.Canvas.play(data=rescale_vecs, fig_type='radar', cvs_main='radar figure', cvs_legend=True, fig_configs=vis.FigConfigs.Radar.update(name=['var1', 'var2', 'var3'], rescale_labels=rescale_params, dim_names=['d1', 'd2', 'd3', 'd4', 'd5'], n_grids=5, pen_grids=cus_pen))
Figure 3.8 canvas used for radar plot¶
For pie plot:
frac = np.array([20, 15, 40, 25]) vis.Canvas.play(data=frac, fig_type='pie', cvs_main='pie figure', cvs_legend=True)
Figure 3.9 canvas used for pie plot¶
For contour plot:
_cont = (lambda x1, x2: (1-x1/2+x1**5+x2**3)*np.exp(-x1**2-x2**2)) dens = _cont(*np.meshgrid(*[np.linspace(-3, 3, 256) for _ in range(2)])) vis.Canvas.play(data=dens, fig_type='contour', fig_configs=vis.FigConfigs.Contour.update(rect=(-3, -3, 6, 6)))
Figure 3.10 canvas used for contour plot¶
Use as an image viewer:
from info.ins import datasets vis.Canvas.play(data=datasets.cat(), fig_type='image', cvs_main='image viewer')
Figure 3.11 canvas used for image viewer¶
- Note:
If
IndexErrorraised, reassignnameinfig_configsbyGrpSettings, or by updating default configuration setFigConfigs.
- See Also:
- Logs:
Added in version 0.0.2.
Changed in version 0.0.3: support heatmap, radar, and pie plot. heuristically guess and configuration of
fig_configs.Changed in version 0.0.4: support writing image via
savemethod. no limitation for 10 groups of data in maximum anymore.Changed in version 0.0.5: support iso contour plot. attach interactive color bar item to heatmap and contour plot. add logic of length check, as well as horizontal label trigger for tags in heatmap.
– Created by Chen Zhang; Last updated on 01:34, 2025-09-06
- class ImageViewer¶
interactive viewer for 3D image.
- Arguments:
- Parameters:
gui_size (tuple[int, int]) – size for main window of application;
(1000, 1000)as default- Returns:
an ImageViewer instance
- Return type:
- Methods:
- view:
view 3D image.
- Variables:
data (ndarray) – 3-dimensional ndarray
mask (Optional[list[ndarray]]) – list of bool ndarray with 3 dimension;
Noneas default for no maskspacing (Iterable[Numeric]) – iterable object with length of 3 to specify spacing values;
(1, 1, 1)as defaultorigin (Iterable[Numeric]) – iterable object with length of 3 to specify origin values;
(0, 0, 0)as defaultimg_title (Optional[str]) – title to be displayed in main window;
Noneas defaultlevels (tuple[Numeric, Numeric]) – initial low and high values of grey level; values should be numeric; if those values range from 0. to 1. simultaneously, grey level percentage will be applied;
(0.688, 0.997)as defaultpalettes (Optional[list[tuple[Numeric, ...]]]) – RGB shader colors if
maskwas assigned; value ranges from 0.0 to 1.0 in each channel;Noneas default for random colors; if specified, substitution for mask shaders takes places sequentially
- play:
static method; create a new ImageViewer then view 3D image. all parameters defined the same as those when calling
view.
- Examples:
from info.vis import ImageViewer img, spacing, origin = ... # ndarray, len(spacing) == 3, len(origin) == 3 # simple 3D image viewer: ImageViewer.play(data=img) # 3D image viewer with spacing: ImageViewer.play(data=img, spacing=spacing) # 3D image viewer with spacing and origin ImageViewer.play(data=img, spacing=spacing, origin=origin)
Following figure for preview:
Figure 3.12 ImageViewer for 3D image¶
Or if the images have the corresponding segmentations:
segs = ... # list of bool ndarray # 3D image viewer with image and segmentations: ImageViewer.play(data=img, spacing=spacing, origin=origin, mask=[segs])
Figure 3.13 ImageViewer for 3D image with segmentation¶
- Logs:
Added in version 0.0.2.
Changed in version 0.0.4: Implementation uses linked views, instead of projection with sliced segmentation line. Support origin, colored segmentations, and 3D visualization with OpenGL rendering.
Changed in version 0.0.5: No limitation for mask numbers during visualization (3 in maximum the former); fix the exception raised in sequential playing.
– Created by Chen Zhang; Last updated on 01:34, 2025-09-06
- Authors:
Chen Zhang
- Version:
0.0.5
- Created on:
Jun 29, 2023