3

I want to make a parametric plot like this:

ParametricPlot[{{2 t, -10 t^2}, {t, 2 t}}, {t, 0, 2}]

I have tried the following but it doesn't work:

ParametricPlot[{{2 t, -10 t^2}, {t, 2 t}}, {{t, 0, 2}, {t, 4, 7}}]
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
user1626227
  • 35
  • 1
  • 4

3 Answers3

8

ConditionalExpression[] works nicely:

ParametricPlot[{ConditionalExpression[{2 t, -10 t^2}, 0 <= t <= 2], 
                ConditionalExpression[{t, 2 t}, 4 <= t <= 7]}, {t, 0, 7}, 
               AspectRatio -> 1/GoldenRatio]

split plots

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
4

Without conditional constructs, just building a list of your functions and limits

intervals = {{{2 t, -10  t^2}, {0, 2}}, {{t, 2 t}, {4, 7}}};
Show[ParametricPlot[#[[1]], Evaluate@{t, Sequence @@ #[[2]]}] & /@  intervals,
     PlotRange -> Automatic, AspectRatio -> 1/GoldenRatio]

Mathematica graphics

Edit You may prefer to use \[FormalT] instead of simply t for protection against possible definitions of t elsewhere.

Edit 2

A more featured implementation, taking the color switching from @Mr's answer and forcing it to cycle so allowing to take any number of curves as argument:

f[{var_, l1_}] := Module[{style = ColorData[1] /@ Range@5},
  Show[ParametricPlot[#[[1]], Evaluate@{var, Sequence @@ #[[2]]}] & /@ l1 /.
       x_Line :> {First@(style = RotateRight[style]), x}, 
       PlotRange -> Automatic, AspectRatio -> 1/GoldenRatio]]

Usage:

l = {\[FormalT],Array[{{RandomInteger[10]\[FormalT],RandomInteger[{-10,10}]   
                    \[FormalT]^RandomReal[2]},RandomInteger[10,2]}&,10]};
f[l]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
3

For version 7 users without ConditionalExpression there is Piecewise:

ParametricPlot[
  Piecewise[{{{2 t, -10 t^2}, 0 <= t <= 2}, {{t, 2 t}, 4 <= t <= 7}}], {t, 0, 7},
  AspectRatio -> 1/GoldenRatio
]

Mathematica graphics

To get separate styles requires additional work:

ParametricPlot[
 pwSplit @ Piecewise[{{{2 t, -10 t^2}, 0 <= t <= 2}, {{t, 2 t}, 4 <= t <= 7}}],
 {t, 0, 7},
 AspectRatio -> 1/GoldenRatio,
 PlotStyle -> {Red, Blue},
 Evaluated -> True
]

Mathematica graphics

pwSplit code from here. Or:

Module[{style = {Red, Blue}, i = 1},
 ParametricPlot[
   Piecewise[{{{2 t, -10 t^2}, 0 <= t <= 2}, {{t, 2 t}, 4 <= t <= 7}}], {t, 0, 7},
   AspectRatio -> 1/GoldenRatio
 ] /. x_Line :> {style[[i++]], x}
]

Mathematica graphics

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371