I have two curves that I wanted to plot where each curve is composed of two functions. As an example, the first curve is the piecewise function $\rm{sin(x)}$ for $x \in [0,5]$ and $(x-5)+\rm{sin}(5)$ for $x \in [5,10]$.
My issue is when plotting it, the PlotLegend
assigns a shorter line on the first curve (solid line) as opposed to the second curve (dashed line). How to fix this?
In addition, is there a way to place the legend inside the plot, in the lower right corner? It's better if there is a way to input coordinates for the position, say $(8,-2)$, so that it's easily adjustable.
p1 = Plot[Sin[x], {x, 0, 5}, Frame -> True, FrameLabel -> {"x", "y"}, LabelStyle -> Directive[Black, 20], PlotStyle -> {Black, Thickness[thickness]}, PlotPoints -> 500, PlotRange -> {{0, 10}, {-3, 3}}, PlotLegends -> Placed[{"Sin(x)"}, Right], AspectRatio -> 3/4, ImageSize -> Large];
p2 = Plot[(x - 5) + Sin[5], {x, 5, 10}, Frame -> True, FrameLabel -> {"x", "y"}, LabelStyle -> Directive[Black, 20], PlotStyle -> {Black, Thickness[thickness]}, PlotPoints -> 500, PlotRange -> {{0, 10}, {-3, 3}}, AspectRatio -> 3/4, ImageSize -> Large];
p3 = Plot[Cos[x], {x, 0, 5}, Frame -> True, FrameLabel -> {"x", "y"}, LabelStyle -> Directive[Black, 20], PlotStyle -> {Black, Dashed, Thickness[thickness]}, PlotPoints -> 500, PlotRange -> {{0, 10}, {-3, 3}}, PlotLegends -> Placed[{"Cos(x)"}, Right], AspectRatio -> 3/4, ImageSize -> Large];
p4 = Plot[(x - 5) + Cos[5], {x, 5, 10}, Frame -> True, FrameLabel -> {"x", "y"}, LabelStyle -> Directive[Black, 20], PlotStyle -> {Black, Dashed, Thickness[thickness]}, PlotPoints -> 500, PlotRange -> {{0, 10}, {-3, 3}}, AspectRatio -> 3/4, ImageSize -> Large];
Show[p1, p2, p3, p4]
PlotLegends -> Placed[{"Sin(x)"}, Scaled[{0.8, 0.1}]]
$\endgroup$PlotStyle->...Dashed..
there is no difference in the length of margins. $\endgroup$PlotLegends -> Placed[LineLegend[{Directive[{Black, Dashed}]}, {"Cos[x]"}, LegendMarkerSize -> 20], Right]
and make the same change to the other entry, removing theDashed
directive. $\endgroup$