2
$\begingroup$

Plot f(x) = x^3 and g(x) = 10e^(−x^2) on the same graph. Make a frame around the graph, show tick labels on all four sides, plot such that f(x)’s ticks appear on the left side of the plot and g(x)’s ticks appear on the right side.

I've tried variations of this

p5 = x^3
p6 = 10*Exp[-x^2]
Plot[{p5, p6}, {x, -1, 1}, Frame -> True, 
FrameTicks -> {{{p5, p6}, {Automatic, Automatic}}}]
$\endgroup$

2 Answers 2

3
$\begingroup$
$Version

"13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)"

Clear["Global`*"]

f[x_] = x^3;
g[x_] = 10*Exp[-x^2];

With v12.0 and later, use ResourceFunction["MultipleAxesPlot"]

Show[
 maplt = ResourceFunction["MultipleAxesPlot"][
   {f[x], g[x]}, {x, -1, 1},
   PlotStyle -> {{GrayLevel[0.3], AbsoluteThickness[1]}, ColorData[97][2]},
   FrameLabel -> {
     {StringForm["`` = ``", HoldForm[f[x]], f[x]], 
      StringForm["`` = ``", HoldForm[g[x]], g[x]]},
     {x, None}},
   "SecondaryAxesColor" -> ColorData[97][2]],
 (Options[maplt, FrameTicks] /. {} :> Automatic)]

enter image description here

$\endgroup$
2
$\begingroup$
p5 = x^3;
p6 = 10*Exp[-x^2];

Find the minimum and maximum values for p5 (yrange5) and p6 (yrange6) and use them (1) to Rescale p6 and (2) to define a ticks function for the right frame:

{yrange5, yrange6} = Through[{MinValue, MaxValue}[{#, -1 <= x <= 1}, x]] & /@ {p5, p6};

rescaledp6 = Rescale[p6, yrange6, yrange5];

rightframeticks = Charting`FindTicks[yrange5, yrange6];

Plot {p5, rescaledp6} with the option FrameTicks -> {{Automatic, rightframeticks}, {Automatic, Automatic}}:

Plot[{p5, rescaledp6}, {x, -1, 1}, 
 Frame -> True, 
 FrameLabel->{{p5, p6}, {x, None}}, 
 FrameStyle -> {ColorData[97] /@ {1, 2}, {Automatic, Automatic}}, 
 FrameTicks -> {{Automatic, rightframeticks}, {Automatic, Automatic}}]

enter image description here

$\endgroup$

Your Answer

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

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