# Half dotted half solid line in Epilog LineLegend

I have a plot in which a function is plotted as dotted line in some domain and solid in another, like this:

function=Plot[{Piecewise[{{x+10,x<0}},None],Piecewise[{{x+10,x>=0}},None]},{x,-9,9},PlotStyle->{Dotted,Black}]


Since I'm plotting multiple functions at the same time I'm using Show and Epilog. For this particular function, I would like the line in the legend to be half dotted and half solid as well (rather than just dotted as below):

Show[function,


How can I can make this happen?

Edit:

Screenshot 1

Screenshot 2

• Not sure why it doesn't work. I will ask the community to please verify it as I see this on my machine.
– Syed
Commented Mar 12, 2022 at 7:49

Edit

Clear["Global*"];
plot1 = Plot[{Piecewise[{{x + 10, x < 0}}, None],
Piecewise[{{x + 10, x >= 0}}, None]}, {x, -9, 9},
PlotStyle -> {Dotted, Red}];
plot2 = Plot[4 Sin[x], {x, -5, 6}, MeshFunctions -> {#1 &},
Mesh -> {{4}}, MeshShading -> {Directive[Dashed, Blue], Green}];
plot = Show[plot1, plot2, PlotRange -> All];
markers1 =
Graphics[{{Dotted, Line[{{0, 0}, {.5, 0}}]}, {Thick, Red,
Line[{{.5, 0}, {1, 0}}]}}];
markers2 =
Graphics[{{Dashed, Blue, Line[{{0, 0}, {.8, 0}}]}, {Thick, Green,
Line[{{.8, 0}, {1, 0}}]}}];

Legended[plot,
Placed[SwatchLegend[{Opacity[1], Opacity[1]}, {Function1, Function2},
LegendMarkers -> {markers1, markers2},
LegendMarkerSize -> {40, 20},
LegendFunction -> (Framed[#, RoundingRadius -> 4,
FrameStyle -> Brown] &)], {.2, .8}]]


Original

plot = Plot[{Piecewise[{{x + 10, x < 0}}, None],
Piecewise[{{x + 10, x >= 0}}, None]}, {x, -9, 9},
PlotStyle -> {Dotted, Red}];

markers =
Graphics[{{Blue, Dotted, Line[{{0, 0}, {.5, 0}}]}, {Thick, Red,
Line[{{.5, 0}, {1, 0}}]}}];
Legended[plot,
Placed[SwatchLegend[{Opacity[1]}, {Function},
LegendMarkers -> markers, LegendMarkerSize -> {40, 20},
LegendFunction -> (Framed[#, RoundingRadius -> 4,
FrameStyle -> Brown] &)], {.2, .8}]]


• Thanks! This works, but how can I make it work within Epilog's LineLegend? As I mentioned above I'm using Show and Epilog to create a plot with multiple graphs/functions, but it seems that Graphics does not work in Epilog's LineLegend, see screenshot 2 above. Commented Mar 12, 2022 at 7:53
• Epilog,Inset,Framed,Show is not the good way to add Legend, we just need to use Legended function to do all this thing. Commented Mar 12, 2022 at 7:59
• OK. How can I use Legended to plot multiple functions? I have looked at the documentation but that does not seem to be its intended use. Commented Mar 12, 2022 at 8:09
• Thanks for the edits. This works great! Commented Mar 13, 2022 at 5:54
Show[function, Epilog -> Inset[Framed[
LineLegend[
{Directive[Black,
Dashing[ConstantArray[0.004, 12]~Join ~
ConstantArray[0.06, 1]]]}, {Text@
Style["Function", Medium, 18, FontFamily -> "Euclid Fraktur"]}
, LegendMargins -> 7
]
]
, {-5, 15.5}, {0, 0}, 50]
]
`

• Unfortunately this does not work for me, see screenshot 1 attached to the original post. Commented Mar 12, 2022 at 7:38
• i.sstatic.net/FbcOR.png
– Syed
Commented Mar 12, 2022 at 7:46
• Any ideas on what the issue might be on my end? Commented Mar 12, 2022 at 7:47
• Use a font like "Times New Roman" or something that is available on your system. It can't be that but let's rule it out.
– Syed
Commented Mar 12, 2022 at 7:51
• OK, done! Unfortunately this didn't fix the problem, but as you said at least we can rule it out now. Commented Mar 12, 2022 at 7:54