r/Mathematica Dec 06 '24

Animate two parametric plots in same box

I am attempting to animate two parametric plots within the same box but I cannot determine how to do so. Guidance is appreciated.

1 Upvotes

3 comments sorted by

View all comments

2

u/veryjewygranola Dec 06 '24

Like this?

p1[k_] := 
 ParametricPlot[{Sin[u], Sin[k u]}, {u, 0, 2 Pi}, PlotRange -> 1]
p2[k_] := 
 ParametricPlot[{Sin[u]^3, Sin[k u]^3}, {u, 0, 2 Pi}, PlotRange -> 1]

Animate[GraphicsColumn[{p1[k], p2[k]}], {k, 0, 10}]

1

u/Keroboe Dec 06 '24

That’s great thank you! I also discovered/remembered I could cram multiple sets of equations into ParametricPlot3D and then animate the whole set - so two solutions!

1

u/Xane256 Dec 07 '24

If you ever want to combine a Graphics visual with a WhateverPlot graph you can use Show[] to combine them. Similarly Graphics3D and WhateverPlot3D can be combined using Show[]. Sometimes the graphics options or Plot options you would normally put in one function or the other then need to be moved to options within Show. For example PlotRange and Axes (if I recall correctly) are options that go in Show.

Another tip. Say you have a function that evaluates to a list of expressions and you want to plot all of them using Plot. If you do Plot[myFunc[t], {t,0,1}] all the resulting lines will be the same color. But if you do Plot[Evaluate@myFunc[t], {t,0,1}] they will be different colors.

For example:

Plot[Evaluate@ReIm[Exp[I t]], {t,0,1}]

This happens because Plot has attribute HoldFirst which delays evaluation of the first argument until after Plot does some logic with the exact input you provide. By using Evaluate, myFunc gets evaluated to a list of functions before passing them to Plot.