Note
Go to the end to download the full example code.
NDWidget image#
NDWidget image example

/home/runner/work/fastplotlib/fastplotlib/fastplotlib/graphics/features/_image.py:205: UserWarning: casting float64 array to float32
warn(f"casting {data.dtype} array to float32")
# test_example = true
import numpy as np
import fastplotlib as fpl
data = np.random.rand(1000, 30, 64, 64)
data2 = np.random.rand(1000, 30, 128, 128)
# must define a reference range for each dim
ref = {
"time": (0, 1000, 1),
"depth": (0, 30, 1),
}
ndw = fpl.NDWidget(
ranges=ref,
size=(700, 560)
)
ndw2 = fpl.NDWidget(
ranges=ref,
indices=ndw.indices, # can create another NDWidget that shared the reference index! So multiple windows are possible
size=(700, 560)
)
ndi = ndw[0, 0].add_nd_image(
data,
("time", "depth", "m", "n"), # specify all dim names
("m", "n"), # specify spatial dims IN ORDER, rest are auto slider dims
name="4d-image",
)
ndi2 = ndw2[0, 0].add_nd_image(
data2,
("time", "depth", "m", "n"), # specify all dim names
("m", "n"), # specify spatial dims IN ORDER, rest are auto slider dims
name="4d-image",
)
# change spatial dims on the fly
# ndi.spatial_dims = ("depth", "m", "n")
figure = ndw.figure
ndw.show()
ndw2.show()
# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()
Total running time of the script: (0 minutes 7.066 seconds)