Combining stories in Mathematica does not produce the expected result

I am trying to combine 3 functions drawn on Plot[] and 1 function depicted on 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 that it gives:

Combined graph

+4
source share
3 answers

Like iodine said, PlotLegends is terrible. However, if you do not mind setting up the graphic styles manually and repeating them later, ShowLegend may 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 the following:

enter image description here

You can also write some simple functions to make this a little less cumbersome if you often run into this problem.

+6
source

Well, the main cause of the error is the PlotLegends package, which is a terrible, buggy package. Having removed this, Show correctly combines them:

 plota = Plot[{-2 x, -2 Sqrt[x], -2 x^(3/5)}, {x, 0, 1}] plotb = ParametricPlot[{2.4056 (u - Sin[u]), 2.4056 (Cos[u] - 1)}, {u, 0, 1.40138}] Show[plota, plotb] 

enter image description here

You can see the Simon solution here so that ideas can label your different curves without using PlotLegends . This James answer also shows why PlotLegends has a reputation that it has ...


You can still save something with the PlotLegends package. Here is an example of using ShowLegends , which you can change to your taste

 colors = {Red, Green, Blue, Pink}; legends = {-2 x, -2 Sqrt[x], -2 x^(3/5), "Problem 3"}; plota = Plot[{-2 x, -2 Sqrt[x], -2 x^(3/5)}, {x, 0, 1}, PlotStyle -> colors[[1 ;; 3]]]; plotb = ParametricPlot[{2.4056 (u - Sin[u]), 2.4056 (Cos[u] - 1)}, {u, 0, 1.40138}, PlotStyle -> colors[[4]]]; ShowLegend[ Show[plota, plotb], {Table[{Graphics[{colors[[i]], Thick, Line[{{0, 0}, {1, 0}}]}], legends[[i]]}, {i, 4}], LegendPosition -> {0.4, -0.15}, LegendSpacing -> 0, LegendShadow -> None, LegendSize -> 0.6}] 

enter image description here

+4
source

As other answers pointed out, the culprit is PlotLegend . Therefore, it is sometimes useful to use your own plot legends:

 plotStyle = {Red, Green, Blue}; labls = {"a", "b", "Let go"}; f[i_, s_] := {Graphics[{plotStyle[[i]], Line[{{0, 0}, {1, 0}}]}, ImageSize -> {15, 10}], Style[labls[[i]], s]}; Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, 0, 2 Pi}, PlotStyle -> plotStyle, Epilog -> Inset[Framed[ Style@Column [{Grid[Table[f[i, 15], {i, 1, 3}]]}]], Offset[{-2, -2}, Scaled[{1, 1}]], {Right, Top}], PlotRangePadding -> 1 ] 

enter image description here

+4
source

Source: https://habr.com/ru/post/1382404/


All Articles