2
$\begingroup$

I want to show my students that $f(x)=2\sin x-3$ and $f^{-1}(x)=\sin^{-1}\dfrac{x+3}{2}$ are inverses of one another via visual evidence; that is, $f$ and $f^{-1}$ are reflections of one another across the line $y=x$. Thus far, I have:

Show[
 Plot[2 Sin[x] - 3, {x, -π/2, π/2},
  AxesOrigin -> {0, 0}],
 Plot[ArcSin[(x + 3)/2], {x, -5, -1}],
 Plot[x, {x, -5, 5}],
 PlotRange -> {{-5, 5}, {-5, 5}},
 AxesLabel -> {"x", "y"},
 AspectRatio -> Automatic
 ]

Which gives this image:

enter image description here

Note that I've restricted $f$ and $f^-1$ to their domains. I'm wondering how I can add plot legends for each curve in this situation.

$\endgroup$
5
$\begingroup$

You can try this (like here):

funcList[x_] = {2 Sin[x] - 3, ArcSin[(x + 3)/2], x};
funcRange = {{-π/2, π/2}, {-5, -1}, {-5, 5}};

Plot[Evaluate@MapThread[ConditionalExpression[#1, First@#2 <= x <Last@#2] &
, {funcList[x],funcRange}], {x, -5, 5}, PlotLegends -> funcList[x]
, AxesLabel -> {"x", "y"}, AspectRatio -> Automatic]

enter image description here

$\endgroup$
  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Sep 26 '16 at 11:49
5
$\begingroup$

I would add PlotLabels to each plot separately:

Show[Plot[2 Sin[x] - 3, {x, -π/2, π/2}, AxesOrigin -> {0, 0}, 
  PlotLabels -> "sin"], 
 Plot[ArcSin[(x + 3)/2], {x, -5, -1}, PlotLabels -> "arcsin"], 
 Plot[x, {x, -5, 5}, PlotLabels -> "x"], 
 PlotRange -> {{-5, 5}, {-5, 5}}, AxesLabel -> {"x", "y"}, 
 AspectRatio -> Automatic]

enter image description here

Or making the plot colorful first:

plot = Show[
  Plot[2 Sin[x] - 3, {x, -π/2, π/2}, AxesOrigin -> {0, 0}, 
   PlotStyle -> Red], 
  Plot[ArcSin[(x + 3)/2], {x, -5, -1}, PlotStyle -> Green], 
  Plot[x, {x, -5, 5}, PlotStyle -> Blue], 
  PlotRange -> {{-5, 5}, {-5, 5}}, AxesLabel -> {"x", "y"}, 
  AspectRatio -> Automatic]

and then using ShowLegend:

Needs["PlotLegends`"]
ShowLegend[plot, {{{Graphics[{Red, Line[{{0, 0}, {2, 0}}]}], 
    "sin"}, {Graphics[{Green, Line[{{0, 0}, {2, 0}}]}], 
    "arcsin"}, {Graphics[{Blue, Line[{{0, 0}, {2, 0}}]}], "x"}}, 
  LegendPosition -> {0.7, 0.2}, LegendSize -> {0.45, 0.4}, 
  LegendShadow -> False}]

enter image description here

Or, to incorporate rcollyer's comment below:

Legended[plot, LineLegend[{Red, Green, Blue}, {"sin", "arcsin", "x"}]]

enter image description here

$\endgroup$
  • 4
    $\begingroup$ ShowLegends is deprecated as of v9. If you're using PlotLabels, then you have v11. So, I'd use Legended[plot, LineLegend[{Red, Green, Blue}, {"sin", "arcsin", "x"}]]. $\endgroup$ – rcollyer Sep 26 '16 at 19:56
  • $\begingroup$ @rcollyer I think that qualifies as an answer. // I was thinking how to show a legend, so ShowLegend naturally came in mind. // Btw, I'm on v10.4 $\endgroup$ – corey979 Sep 26 '16 at 20:00
  • $\begingroup$ huh. The versions just sort of blur together after a while. $\endgroup$ – rcollyer Sep 26 '16 at 20:53

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.