.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/3Dvispy/15_3D_rgb_volume.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_3Dvispy_15_3D_rgb_volume.py: 3D RGB/RGBA volume, i.e., 4D array ======================================== Display a 3D RGB/RGBA volume, whose shape could be (ni, nx, nt, 3/4) or (3/4, ni, nx, nt). This would be useful for analyzing the inner features of a deep 3D network (using PCA to keep the most important three features). .. image:: ../../_static/cigvis/3Dvispy/15.png :alt: image :align: center .. GENERATED FROM PYTHON SOURCE LINES 17-46 .. code-block:: Python # sphinx_gallery_thumbnail_path = '_static/cigvis/3Dvispy/15.png' import numpy as np import cigvis from pathlib import Path root = Path(__file__).resolve().parent.parent.parent seisp = root / 'data/co2/sx.dat' ni, nx, nt = 192, 192, 240 data = np.fromfile(seisp, np.float32).reshape(ni, nx, nt) data = (data - data.min()) / (data.max() - data.min()) ### FP32, RGBA volume's range should be in [0, 1] sx = np.zeros((ni, nx, nt, 4)).astype(np.float32) sx[:, :, :, 0] = data sx[:, :, :, 1] = data + 0.2 sx[:, :, :, 2] = data - 0.2 sx[:, :, :, 3] = np.random.randn(ni, nx, nt) sx = np.clip(sx, 0, 1) ### UINT8, RGBA volume's range should be in [0, 255] sx = (sx * 255).astype(np.uint8) ### `cmap` will be ignored nodes = cigvis.create_slices(sx, pos=[[10, ni//2, ni-10], [10, nx//2, nx-10], [10, nt//2, nt-10]]) cigvis.plot3D(nodes, view=cigvis.Plot3DView(size=(700, 600))) .. _sphx_glr_download_gallery_3Dvispy_15_3D_rgb_volume.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 15_3D_rgb_volume.ipynb <15_3D_rgb_volume.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 15_3D_rgb_volume.py <15_3D_rgb_volume.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 15_3D_rgb_volume.zip <15_3D_rgb_volume.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_