Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

A program I'm running requires me to generate multiple plots over the same domain, so I thought it would be fairly simple to use a module and bury all of the plot commands within that that way I only have to call the function and domain once and I can generate all of my plots without having to go and change the domain every time.

This has worked, but the plots always come out small and inline, and I was wondering if there was a way for me to tell Mathematica I wanted each plot in its own output that way it would be the same size as if I had just called the plot command.

This is what I'm using:

Plots[o_,r_,t_ :50]:= Module[{a,b,c,d},
  a = Plot[f1[x],{x,o,r},Ticks->{{t,2t,3t,4t,5t,6t,7t,8t,9t,10t},{0,0.2,0.4,0.6,0.8,1}}, PlotLabel->"Plot1";
  b = Plot[f2[x],{x,o,r},Ticks->{{t,2t,3t,4t,5t,6t,7t,8t,9t,10t},{0,0.2,0.4,0.6,0.8,1}}, PlotLabel->"Plot2";
  c= Plot[f3[x],{x,o,r},Ticks->{{t,2t,3t,4t,5t,6t,7t,8t,9t,10t},{0,0.2,0.4,0.6,0.8,1}}, PlotLabel->"Plot3";
  d=Plot[f4[x],{x,o,r},Ticks->{{t,2t,3t,4t,5t,6t,7t,8t,9t,10t},{0,0.2,0.4,0.6,0.8,1}}, PlotLabel->"Plot4";
  Print[a,b,c,d]
]

If anyone has any better suggestions for how I can output my plots I'd greatly appreciate it.

share|improve this question
    
1. Use something like GraphicsGrid, not Print. 2. Your code is incomplete (perhaps copy-n-paste error), so it's not runnable. 3} Your code is incomplete - what are the definitions of the f1.... –  ciao Apr 17 at 22:48
1  
And why do you want to make the range of ticks unrelated to the domain of the function? If o = 0, r = 1 and t=50, then your Ticks go to 500 while the function only goes to x = 1. Please fix your question! –  David G. Stork Apr 17 at 22:57
    
I would say that the ticks are a trivial, localized side issue to the main question, which seems to be how to get each of several plots in a regular output cell. –  Michael E2 Apr 18 at 2:05
    
The functions that I'm plotting aren't really relevant to the quesiton which is why I didn't post them. You can insert x, x^2, -x, 1-x for the if you like. Makes no difference. –  CosmoSounder Apr 18 at 16:37
    
I can define t to be whatever i want it just defaults to 50. I have the huge range in ticks that may or may not go beyond my domain I know that my entire domain will be ticked in the incroments that I want. This again isn't really relevant to my question, just a personal preference for how I want my graphs displayed –  CosmoSounder Apr 18 at 16:40

2 Answers 2

You can use CellPrint together with ExpressionCell:

Plots[o_, r_, t_ : 50] := 
 Module[{a, b, c, d}, 
  a = Plot[f1[x], {x, o, r}, 
    Ticks -> {{t, 2 t, 3 t, 4 t, 5 t, 6 t, 7 t, 8 t, 9 t, 10 t}, {0, 
       0.2, 0.4, 0.6, 0.8, 1}}, PlotLabel -> "Plot1"];
  b = Plot[f2[x], {x, o, r}, 
    Ticks -> {{t, 2 t, 3 t, 4 t, 5 t, 6 t, 7 t, 8 t, 9 t, 10 t}, {0, 
       0.2, 0.4, 0.6, 0.8, 1}}, PlotLabel -> "Plot2"];
  c = Plot[f3[x], {x, o, r}, 
    Ticks -> {{t, 2 t, 3 t, 4 t, 5 t, 6 t, 7 t, 8 t, 9 t, 10 t}, {0, 
       0.2, 0.4, 0.6, 0.8, 1}}, PlotLabel -> "Plot3"];
  d = Plot[f4[x], {x, o, r}, 
    Ticks -> {{t, 2 t, 3 t, 4 t, 5 t, 6 t, 7 t, 8 t, 9 t, 10 t}, {0, 
       0.2, 0.4, 0.6, 0.8, 1}}, PlotLabel -> "Plot4"];
  CellPrint@ExpressionCell[#, "Output"] & /@ {a, b, c, d};
  ]

Example:

Block[{f1 = Sin, f2 = Exp[#/20] - 1 &, f3 = #^3/1000 &, f4 = Tan[#]/10 &},
 Plots[0, 10, 1]
 ]

Mathematica graphics

share|improve this answer
    
Try Block[{f1 = Sin, f2 = Exp[#/20] - 1 &, f3 = #^3/1000 &, f4 = Tan[#]/10 &}, Plots[0, 10, 50]] to see that the result is surely not what the question poser seeks. –  David G. Stork Apr 18 at 0:05
    
@DavidG.Stork Why would you use a default tick spacing of 50 on a domain of length 10? I figure that's why the OP made t an argument. I think the OP probably does want 50 because it makes sense for his or her typical domain & units. I also figure that the vertical ticks makes sense because the OP is plotting concentrations or something like that. I just didn't want to fuss too much figuring out suitable test functions simply for a proof-of-concept example. –  Michael E2 Apr 18 at 1:57
    
@CosmoSounder BTW, the use of the variables a, b, c, d is unnecessary in the code sample. One can directly print a cell with something like CellPrint@ExpressionCell[Plot[...], "Output"]; for each plot. –  Michael E2 Apr 18 at 2:04

I am assuming your inclusion of t is an error. There is no reason you would want the range of ticks to be unrelated to the domain of your plots. (Your question would allow the plot to be between x = 0 and x = 1 and your Ticks go up to 500, for instance.) Perhaps you want to set number of ticks to be t.

Here's what I think you want:

f[x_] := {x^2, x^3, x^4, x^5};
myPlots[o_, r_, t_: 50] := Module[{ },
  SetOptions[Plot, ImageSize -> 200, 
   Ticks -> {N@Range[o, r, (r - o)/t], Range[0, 1, .2]}];
  Row[Table[Plot[f[x][[i]], {x, o, r}], {i, 1, 4}]]];

myPlots[0, 1, 10]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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