# How to differentiate the plots with different line style when the functions are touching x axis simultaneously

I am trying to represent four functions with different plot styles, But when the functions touch x-axis, it is becoming difficult to distinguish the functions. how to overcome this problem?. I tried shifting the functions in y-axis, but the moment when I use PlotRange ->All the problem reappears.

m1 = Piecewise[{{-1.8520469275761053*^-27 Cos[
5.347391750782036 x] +
6.642144655629139*^-12 Sin[5.347391750782036 x],
x <= 0.4125}, {5.347112918701602*^-12 Cos[
5.347391750782036 (-0.4125 + x)] +
1. Sin[5.347391750782036 (-0.4125 + x)], x > 0.4125}}];

m2 = Piecewise[{{2.70223120312319*^-16 Cos[7.615982190502248 x] +
1. Sin[7.615982190502248 x],
x <= 0.4125}, {7.615982194424732*^-12 Cos[
7.615982190502248 (-0.4125 + x)] -
1.8475302667032957*^-12 Sin[7.615982190502248 (-0.4125 + x)],
x > 0.4125}}];

m3 = Piecewise[{{6.244447705938866*^-27 Cos[10.694783501564071 x] -
1.1197524383853221*^-11 Sin[10.694783501564071 x],
x <= 0.4125}, {1.06942258373537*^-11 Cos[
10.694783501564071 (-0.4125 + x)] +
1. Sin[10.694783501564071 (-0.4125 + x)], x > 0.4125}}];

m4 = Piecewise[{{-5.404457624399228*^-16 Cos[
15.231964381004495 x] - 1. Sin[15.231964381004495 x],
x <=
0.4125}, {1.523196438056986*^-11 Cos[
15.231964381004495 (-0.4125 + x)] +
2.954602052227571*^-11 Sin[15.231964381004495 (-0.4125 + x)],
x > 0.4125}}];

s = PlotStyle -> {Black, Thickness[0.004], AbsoluteDashing[{2, 7}]};
s = PlotStyle -> {Black, Thickness[0.004],
AbsoluteDashing[{8, 20}]};
s = PlotStyle -> {Black, Thickness[0.004],
AbsoluteDashing[{4, 18, 40}]};
s = PlotStyle -> {Black, Thickness[0.004]};

p = Plot[m1, {x, 0, L1}, Evaluate@s];
p = Plot[m2, {x, 0, L1}, Evaluate@s];
p = Plot[m3, {x, 0, L1}, Evaluate@s];
p = Plot[m4, {x, 0, L1}, Evaluate@s];
p = Table[
Show[p[i] /. {x_Real, y_Real} :> {x/L1,
y/Max@Abs@Last@PlotRange@p[i]}, PlotRange -> All], {i, 1, 4}]

Show[p, PlotRange -> All]

• Cant, we customize the style according to our requirements. because the rest of the plot in my paper is in the plot style that I defined using AbsoulteDashing. I would be easy if I change this one plot according to the style I defined. – Vijay Kumar S Apr 4 at 7:55

See if this can be of any help. A slightly modified version of kglr's first plot.

I have tried to use complementary colors and a mixture of dashed lines with solid ones. You can choose your color combination.

L1 = 1;
Plot[{m1, m2, m3, m4}, {x, 0, L1},
PlotStyle -> {
Directive[AbsoluteThickness, Opacity, Red, Dashed],
Directive[AbsoluteThickness, Opacity[.6], Darker@Blue],
Directive[AbsoluteThickness, Opacity[.6], Darker@Yellow],
Directive[AbsoluteThickness, Opacity, Green, Dashed]},
ImageSize -> Large, PlotRange -> All, PlotLegends -> "Expressions",
Axes -> False, Frame -> True] Update: "... change this one plot according to the style I defined"

If you replace PlotTheme -> "Monochrome" in methods 1 and 2 in the original answer with

PlotStyle -> (PlotStyle /. ( {s@#} & /@ Range))


method 1 gives: and method 2 gives: Assuming a monochrome plot is desired, you can use the options Axes -> False and PlotTheme -> "Monochrome" and

1. shift each function vertically by a small amount:

Plot[{m1 + .01, m2 + .01, m3 - .01, m4 - .01}, {x, 0, 1},
PlotTheme -> "Monochrome", ImageSize -> Large, PlotRange -> All,
PlotLegends -> {"m1", "m2", "m3", "m4"}, Axes -> False, Frame -> True] 2. perturb only the flat portions of the lines slightly:

plot = Chop @ Plot[{m1, m2, m3, m4}, {x, 0, 1}, PlotTheme -> "Monochrome",
ImageSize -> Large, PlotRange -> All,
PlotLegends -> "Expressions", Axes -> False, Frame -> True];

pairs = GatherBy[Cases[plot, Line[{{_, 0} ..}], All] , #[[1, 1]] &];

perturb[prs_, δ_: .01] := ReplaceAll[Join @@
({# -> Translate[#, {0, δ}], #2 -> Translate[#2, {0, -δ}]} & @@@ prs)];

perturb[pairs] @ plot 3. play with thickness and opacity combinations in setting PlotStyle:

Plot[{m1, m2, m3, m4}, {x, 0, 1},
PlotTheme -> "Monochrome",
PlotStyle -> {Directive[CapForm["Round"], AbsoluteThickness, Opacity[.7]],
Directive[CapForm["Round"], AbsoluteThickness, Opacity[.3]],
Directive[CapForm["Round"], AbsoluteThickness, Opacity[.5]],
Directive[AbsoluteThickness, Opacity]}, ImageSize -> Large,
PlotRange -> All, PlotLegends -> "Expressions", Axes -> False, Frame -> True] • not OP, but maybe also include colors to enhance distinguishability? – exp ikx Apr 4 at 8:11
• @expikx, good point. I assumed a monochrome plot is desired. If colors are allowed it would be much easier to distinguish the curves. – kglr Apr 4 at 9:57

When one plots several functions that are equal in some domains, the problem is that the markers (and also mesh, dashing ...) are exactly at the same place for each function, so they hide each others.

Here is a solution that usesParametricPlot instead of Plot to create a offset between the mesh-points of each function.

L1 = 1;
offset = 0.1;
gr=ParametricPlot[Evaluate[{{x, m1}
, {x, m2 } /. {x -> offset + x}
, {x, m3 } /. {x -> 2 offset + x}
, {x, m4 } /. {x -> 3 offset + x}
}]
, {x, -0.5, L1}
, AspectRatio -> 1, ImageSize -> 300,
PlotRange -> {{0, 1}, Automatic}, Mesh -> 10,
MeshStyle -> AbsolutePointSize,
PlotStyle -> {Black, Red, Green, Blue}]


I prefer to have a distinct marker shape for each function. Here is a try and error postprocessing approach :

Extract the points from the graphic :

 Cases[gr, Point[___], {1, -1}]


{Point[{2727, 2728, 2729, 2730, 2731, 2732, 2733, 2734, 2735, 2736}],

Point[{2737, 2738, 2739, 2740, 2741, 2742, 2743, 2744, 2745, 2746}],
Point[{2747, 2748, 2749, 2750, 2751, 2752, 2753, 2754, 2755, 2756}],
Point[{2757, 2758, 2759, 2760, 2761, 2762, 2763, 2764, 2765, 2766}]}

There are four series of points corresponding to the four functions. These points can be replaced by something else, say Inset[]. One can copy-paste this serie of points and apply a rule on it :

gr/. Point[data : {2727, 2728, 2729, 2730, 2731, 2732, 2733, 2734, 2735,
2736}] :> (Inset["X", #] & /@ data) If colors are allowed:

You can post-process Plot output to make one the coincident lines dashed so that both lines are visible:

ClearAll[makedashed]
makedashed[prs_, dashing_: {20, 20}] := ReplaceAll[#2 ->
{AbsoluteDashing[dashing], #2} & @@@ prs] @* Chop

pairs = GatherBy[Cases[Chop @ plt, Line[{{_, 0} ..}], All], #[[1, 1]] &];

plt = Plot[{m1, m2, m3, m4}, {x, 0, 1},
PlotStyle -> (Directive[Opacity, AbsoluteThickness, #] & /@
{Red, Green, Blue, Purple}),
ImageSize -> Large, Axes -> False, Frame -> True, PlotLegends -> "Expressions"];

makedashed[pairs] @ plt • So far I the customized line style I have defined cannot be implemented in the above suggested answer – Vijay Kumar S Apr 5 at 6:14
• @VijayKumarS, please see the update to my previous answer. – kglr Apr 5 at 6:36