Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Plots in Mathematica is not giving the expected result

I'm trying to combine 3 functions graphed on a Plot[] and 1 function graphed on a ParametricPlot[]. My equations are as follows:

plota = Plot[{-2 x, -2 Sqrt[x], -2 x^(3/5)}, {x, 0, 1}, PlotLegend -> {"-2 x", "-2 \!\(\*SqrtBox[\(x\)]\)", "-2 \!\(\*SuperscriptBox[\(x\), \(3/5\)]\)"}]
plotb = ParametricPlot[{2.4056 (u - Sin[u]), 2.4056 (Cos[u] - 1)}, {u,0, 1.40138}, PlotLegend -> {"Problem 3"}]
Show[plota, plotb]

This is the image it gives:

Combined Graph

like image 805
Caleb Jares Avatar asked Dec 10 '22 04:12

Caleb Jares


1 Answers

As yoda said, PlotLegends is terrible. However, if you don't mind setting the plot styles manually and repeating them lateron, ShowLegend can help.

 plota = Plot[{-2 x, -2 Sqrt[x], -2 x^(3/5)}, {x, 0, 1}, 
              PlotStyle -> {{Red}, {Blue}, {Orange}}];
 plotb = ParametricPlot[{2.4056 (u - Sin[u]), 2.4056 (Cos[u] - 1)}, {u, 0, 1.40138}, 
                        PlotStyle -> {{Black}}];

And now

ShowLegend[Show[plota, plotb], 
          {{{Graphics[{Red, Line[{{0, 0}, {1, 0}}]}], Label1},          
            {Graphics[{Blue, Line[{{0, 0}, {1, 0}}]}], Label2},
            {Graphics[{Orange, Line[{{0, 0}, {1, 0}}]}], Label3}, 
            {Graphics[{Black, Line[{{0, 0}, {1, 0}}]}], Label4}},
           LegendSize -> {0.5, 0.5}, LegendPosition -> {0.5, -0.2}}]

which will give you this:

enter image description here

You can also write some simple functions to make this a little less cumbersome, if you deal with this problem often.

like image 185
bbtrb Avatar answered Apr 12 '23 23:04

bbtrb