The animations introduced in the recent versions on MATLAB with Animated Line and Comet/Comet3 can now easily be ported to Plotly. This is currently only supported in the Offline mode. Using Plotly with MATLAB in offline mode is explained in great detail here.
The following code in MATLAB R2021a results in the animation shown below:
t = 0:pi/50:2*pi;
x = cos(t);
y = sin(t);
comet(x,y);
Porting this to Plotly is as simple as adding a single line using the TreatAs parameter:
fig2plotly(gcf, 'Offline', true, 'TreatAs', 'comet');
The command creates and opens up a locally created HTML file in your default browser containing the Plotly animation. By default, it creates Play
and Pause/Stop
buttons for controlling the animation below the plot.
Other similar examples:
Sample code 2:
t = 0:pi/200:2*pi;
x = cos(3*t);
y = sin(2*t).*cos(3*t);
comet(x,y);
fig2plotly(gcf, 'Offline', true, 'TreatAs', 'comet');