2
$\begingroup$

I define a simple function that returns variables storing plots:

MyPlot[a_, b_] := Module[{plot1, plot2},
  plot1 = Plot[Sin[x - a], {x, 0, Pi}, PlotRange -> All];
  plot2 = Plot[Cos[x - b], {x, 0, Pi}, PlotRange -> All];
  {plot1, plot2}
]

When I run it

plots = MyPlot[1, 2]

the plots are stored in plots but are also displayed in the output.

How to prevent the latter and have the plots only stored in plots without being explicitly plotted in the output?

I tried to add DisplayFunction->Identity but it doesn't work.

$\endgroup$
1
  • 3
    $\begingroup$ Semicolon should do the job plots = MyPlot[1, 2]; $\endgroup$
    – yarchik
    Commented Jun 19 at 9:38

1 Answer 1

3
$\begingroup$

Use Hold

MyPlot[a_, b_] := Module[{plot1, plot2},
  plot1 = Plot[Sin[x - a], {x, 0, Pi}, PlotRange -> All];
  plot2 = Plot[Cos[x - b], {x, 0, Pi}, PlotRange -> All];
  Hold[{plot1, plot2}]
]

plots = MyPlot[1, 2]

Hold[{plot1$2326056, plot2$2326056}]

plots // ReleaseHold

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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