diff --git a/doc/python/animations.md b/doc/python/animations.md index 045111c90e7..e76101cb41c 100644 --- a/doc/python/animations.md +++ b/doc/python/animations.md @@ -30,6 +30,7 @@ jupyter: order: 1 page_type: example_index permalink: python/animations/ + redirect_from: python/visualizing-mri-volume-slices/ thumbnail: thumbnail/animations.gif --- @@ -171,7 +172,7 @@ fig = go.Figure( fig.update_layout(width=600, height=450, xaxis=dict(range=[xm, xM], autorange=False, zeroline=False), yaxis=dict(range=[ym, yM], autorange=False, zeroline=False), - title_text="Kinematic Generation of a Planar Curve", title_x=0.5, + title_text="Kinematic Generation of a Planar Curve", title_x=0.5, updatemenus = [dict(type = "buttons", buttons = [ dict( @@ -179,9 +180,9 @@ fig.update_layout(width=600, height=450, "fromcurrent": True, "transition": {"duration": 10}}], label = "Play", method = "animate", - + )])]) - + fig.update(frames=[go.Frame( data=[go.Scatter( x=[xx[k]], diff --git a/doc/python/visualizing-mri-volume-slices.md b/doc/python/visualizing-mri-volume-slices.md deleted file mode 100644 index 63bf99e0627..00000000000 --- a/doc/python/visualizing-mri-volume-slices.md +++ /dev/null @@ -1,144 +0,0 @@ ---- -jupyter: - jupytext: - notebook_metadata_filter: all - text_representation: - extension: .md - format_name: markdown - format_version: '1.1' - jupytext_version: 1.2.3 - kernelspec: - display_name: Python 3 - language: python - name: python3 - language_info: - codemirror_mode: - name: ipython - version: 3 - file_extension: .py - mimetype: text/x-python - name: python - nbconvert_exporter: python - pygments_lexer: ipython3 - version: 3.7.3 - plotly: - description: How to create an plotly animation with slider that cycles through - MRI cross-sections of a human brain. - display_as: animations - language: python - layout: base - name: Visualizing MRI Volume Slices - order: 4 - page_type: example_index - permalink: python/visualizing-mri-volume-slices/ - thumbnail: thumbnail/brain-mri-animation_square.gif ---- - -#### Visualization of MRI volume slices - -```python -# Import data -import time -import numpy as np - -from skimage import io - -vol = io.imread("https://s3.amazonaws.com/assets.datacamp.com/blog_assets/attention-mri.tif") -volume = vol.T -r, c = volume[0].shape - -# Define frames -import plotly.graph_objects as go -nb_frames = 68 - -fig = go.Figure(frames=[go.Frame(data=go.Surface( - z=(6.7 - k * 0.1) * np.ones((r, c)), - surfacecolor=np.flipud(volume[67 - k]), - cmin=0, cmax=200 - ), - name=str(k) # you need to name the frame for the animation to behave properly - ) - for k in range(nb_frames)]) - -# Add data to be displayed before animation starts -fig.add_trace(go.Surface( - z=6.7 * np.ones((r, c)), - surfacecolor=np.flipud(volume[67]), - colorscale='Gray', - cmin=0, cmax=200, - colorbar=dict(thickness=20, ticklen=4) - )) - - -def frame_args(duration): - return { - "frame": {"duration": duration}, - "mode": "immediate", - "fromcurrent": True, - "transition": {"duration": duration, "easing": "linear"}, - } - -sliders = [ - { - "pad": {"b": 10, "t": 60}, - "len": 0.9, - "x": 0.1, - "y": 0, - "steps": [ - { - "args": [[f.name], frame_args(0)], - "label": str(k), - "method": "animate", - } - for k, f in enumerate(fig.frames) - ], - } - ] - -# Layout -fig.update_layout( - title='Slices in volumetric data', - width=600, - height=600, - scene=dict( - zaxis=dict(range=[-0.1, 6.8], autorange=False), - aspectratio=dict(x=1, y=1, z=1), - ), - updatemenus = [ - { - "buttons": [ - { - "args": [None, frame_args(50)], - "label": "▶", # play symbol - "method": "animate", - }, - { - "args": [[None], frame_args(0)], - "label": "◼", # pause symbol - "method": "animate", - }, - ], - "direction": "left", - "pad": {"r": 10, "t": 70}, - "type": "buttons", - "x": 0.1, - "y": 0, - } - ], - sliders=sliders -) - -fig.show() -``` - -#### Credit: -All credit goes to Emilia Petrisor for this excellent animation! - -Here's where you can find her: -- Her [Twitter](https://twitter.com/mathinpython) under the handle `@mathinpython` -- Her [GitHub Page](https://github.com/empet) with Username `empet` - - -#### Reference -For additional information and help setting up a slider in an animation, see https://plotly.com/python/gapminder-example/. For more documentation on creating animations with Plotly, see https://plotly.com/python/#animations. -