Search code examples
wolfram-mathematicaplotaxes

Mathematica Manipulate Plot: Scaling Axes


Say I have set up the following function f[a,b,c] which I wish to plot while varying a and b

f[a_,b_,c_]:=a b c Exp[a b]

Manipulate[
Plot
[
f[a,b,c],
{c,0,1},
PlotRange->{{0,0.05},Automatic}
],
{a,0,1},
{b,0,1}
]

Is it possible to have the ordinate scaled automatically when I fix the abscissa viewing range? You'll notice with the code above that when varying a and b the ordinate does scale automatically as if I were viewing the whole range of {c,0,1}. I would like it to still handle c from 0 to 1, but if I want to view a smaller section of this plot, say c from 0 to 0.05, still have the vertical axis scaled correctly. Thank you all for your help.


Solution

  • A variant on Artes Docendo's suggestion:

    Manipulate[
     Plot[f[a, b, c], {c, 0, Evaluate@d}, 
      PlotRange -> {{0, Evaluate@d}, Full}], {a, 0., 1.}, {b, 0., 1.}, {d, 
      0.05, 1.}]
    

    Notice the Evaluate to force the machine-precision value to be fed to the Plot function before it actually tries to draw something.

    I prefer Full instead of Automatic for the y-axis PlotRange in cases like this, because then you know it will never crop the plot in ways that hide parts of the curve.