2
$\begingroup$

The manipulate function in Mathematica allows the users to adjust the values of the parameters in a graphical way. How do I plot multiple functions in a same graph and also I can use manipulate at the same time?

Manipulate[
 Row[{
   Plot[f1(x+n)], {x, 
     0.0001, 1}, PlotRange -> {-10, 10}],
   Plot[f2(x+n)], {x, 
     0.0001, 1}, PlotRange -> {-10, 10}]}],
   {n, 1, 10}]

with give two independent plots with single curve in each. How should I do multiple curve in a same plot?

$\endgroup$

migrated from stackoverflow.com Jul 16 '14 at 15:49

This question came from our site for professional and enthusiast programmers.

1
$\begingroup$

Like this?

f1[x_] := x^2;
f2[x_] := x^4;
Manipulate[
 Plot[{f1[x + n], f2[x + n]}, {x, 0.0001, 1}, PlotRange->{-10, 10}],
 {n, 1, 10}]

The documentation for Plot shows an example of doing exactly this on the second line. Plot

$\endgroup$
  • $\begingroup$ and how to indicate which is which? $\endgroup$ – user3222184 Jul 14 '14 at 1:22
  • $\begingroup$ You could try adding ,PlotLegends->LineLegend["Expressions"] after your PlotRange, but I tend to see the more you have to fiddle with your plot to make it look like you think it must the more grief you will have. And I don't even try to help with that. $\endgroup$ – Bill Jul 14 '14 at 7:45
1
$\begingroup$

Using Bill's answer but adding Epilog[] for labeling, try

f1[x_] := x^2;
f2[x_] := x^4;
Manipulate[
 Plot[{f1[x + n], f2[x + n]}, {x, 0.0001, 1}, 
  PlotStyle -> {Red, Blue}, PlotRange -> {-10, 10}, Epilog -> {
    (Text[
      Style["f1", FontFamily -> "Times New Roman", FontSize -> 10, 
       Red], {.6, f1[n + .6] + .6}]),
    (Text[
      Style["f2", FontFamily -> "Times New Roman", FontSize -> 10, 
       Blue], {.6, f2[n + .6] + .6}])
    }], {n, 1, 10}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.