4
$\begingroup$

I have plotted 3 graphs which are very close to each other. For example, assume I want to display three functions $\sin(x)$, $\sin(x)+0.0001$ and $\sin(x)+0.0002$ together.

plot1 = Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotStyle -> Blue, 
   AxesLabel -> {"x", "sin(x)"}, PlotLabel -> "Plot of sin(x)"];
plot2 = Plot[Sin[x] + 0.0001, {x, -2 Pi, 2 Pi}, PlotStyle -> Red, 
   AxesLabel -> {"x", "sin(x)"}, PlotLabel -> "Plot of sin(x)"];
plot3 = Plot[Sin[x] + 0.0002, {x, -2 Pi, 2 Pi}, PlotStyle -> Green, 
   AxesLabel -> {"x", "sin(x)"}, PlotLabel -> "Plot of sin(x)"];
Show[
 {plot1, plot2, plot3},
 PlotLabel -> Style["Plots", Black, 13, Bold] ]

The output is the following image. No matter how much I zoom into it they are indistinguishable.

enter image description here

I'm wondering if it is possible to make these graphs distinguishable in Mathematica. For example is it possible to do something like the following image,

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ Normally, one plots just one function and differences to it. $\endgroup$
    – yarchik
    Dec 22, 2023 at 17:43
  • $\begingroup$ To echo @yarchik if you have two aspects of data or a function you want to emphasize, you need two figures despite what some journal editors want. $\endgroup$
    – JimB
    Dec 22, 2023 at 18:01
  • $\begingroup$ The usual approach is to plot the differences $\{f_1(x)-f_2(x),f_1(x)-f_3(x)\}$. $\endgroup$ Dec 22, 2023 at 20:20

6 Answers 6

3
$\begingroup$

PlotHighlighting

curves[x_] := {Sin[x], Sin[x] + 0.0001, Sin[x] + 0.0002};

plotHighlighting = {
  {"Dropline", <|"Style" -> AbsolutePointSize[12]|>}, 
   {"XYLabel", <|Appearance -> None, 
     LabelingFunction -> (Module[{xx = ToExpression @ First @ #}, 
         Plot[Evaluate @ curves @ x, {x, xx - Pi/10000, xx + Pi/10000}, 
          ImageSize -> 100, 
          PlotRange -> {{xx - Pi/10000, xx + Pi/10000}, All}, 
          Axes -> False, PlotStyle -> {Blue, Red, Green}]] &)|>}};

Plot[Evaluate @ curves @ x, {x, -2 Pi, 2 Pi}, 
 PlotStyle -> MapThread[{Opacity[1], AbsoluteThickness[#], #2} &, 
    {{3, 3, 1}, {Blue, Red, Green}}], AxesLabel -> {"x", "sin(x)"}, 
 ImageSize -> Large,  
 PlotHighlighting -> plotHighlighting, 
 PlotLabel -> "Plot of sin(x)"]

enter image description here

enter image description here

To get a variation on Ulrich's approach, use

Plot[Evaluate @ curves @ x, {x, -2 Pi, 2 Pi}, 
 PlotStyle ->  
  MapThread[{Opacity[1], AbsoluteDashing[#], AbsoluteThickness[3], #2} &, 
   {{{}, {10, 10}, {10, 20}}, {Blue, Red, Green}}], 
 AxesLabel -> {"x", "sin(x)"}, 
 ImageSize -> Large, 
 PlotHighlighting -> plotHighlighting, 
 PlotLabel -> "Plot of sin(x)"]

enter image description here

$\endgroup$
8
$\begingroup$
  • Maybe subgraph.
Clear[subgraph]; 
subgraph[t_] := 
 Plot[{Sin[x], Sin[x] + 0.0001, Sin[x] + 0.0002}, {x, -2 Pi, 2 Pi}, 
  Axes -> None, 
  PlotRange -> ({{t - .001, t + .001}, {Sin[t] - .001, 
      Sin[t] + .001}})];
Manipulate[
 Plot[{Sin[x], Sin[x] + 0.0001, Sin[x] + 0.0002}, {x, -2 Pi, 2 Pi}, 
  PlotStyle -> {{Thickness[.01], Blue}, {Thickness[.01], 
     Red}, {Thickness[.01], Green}}, AxesLabel -> {"x", "sin(x)"}, 
  PlotLabel -> "Plot of sin(x)", 
  Epilog -> {Inset[subgraph[t], {5, .5}, Automatic, 3], 
    Arrow[{{t, Sin[t]}, {5, .5}}]}], {t, -2 π, 2 π}]

enter image description here

$\endgroup$
2
  • $\begingroup$ I like this very much! $\endgroup$ Dec 22, 2023 at 16:03
  • $\begingroup$ @cvgmt Ok now you're just showing off :P :-) $\endgroup$
    – Hans Olo
    Dec 23, 2023 at 15:40
5
$\begingroup$

The difference between the curves is much smaller than the thickness of each curve! If you want to distinguish these curves, then each curve would have to be about 100 times thinner. In that case, they will be too thin to see!

Doesn't seem like what you want, but you could subtract $\sin x$ from each curve.

Or, just like in the example you show, you could zoom in to a smaller range.

 Show[{plot1, plot2, plot3}, PlotRange -> {{-.005, .01}, {0, .01}}, 
      PlotLabel -> Style["Plots", Black, 13, Bold], Frame -> True,Axes->False]

enter image description here

$\endgroup$
4
$\begingroup$

Perhaps something like

Plot[{Sin[x], Sin[x] + 0.0001, Sin[x] + 0.0002}, {x, -2 Pi, 2 Pi}, 
 PlotStyle -> {{ Thickness[.01], Blue}, {Thickness[.01], Dashed, 
    Red}, {Thickness[.01], Dotted, Green}}, 
 AxesLabel -> {"x", "sin(x)"}, PlotLabel -> "Plot of sin(x)"] 

enter image description here

$\endgroup$
3
$\begingroup$

You could use ListPlot with appropriate PlotMarkers

a = Table[Sin[x], {x, -2 Pi, 2 Pi, Pi/8}];
b = a + 0.0001;
c = a + 0.0002;

ListPlot[{a, b, c},
 Joined -> {True, False, False},
 PlotMarkers ->
  {Style["\[EmptyCircle]", 22, Red],
   Style["\[EmptyCircle]", 14, Darker@Green],
   Style[\[FilledCircle], 6, Blue]},
 PlotLegends -> Automatic,
 PlotRangePadding -> {1, 0.1}]

enter image description here

Shapes and Icons

$\endgroup$
1
$\begingroup$

Copy code lines and run using only a narrow domain interval to hover the mouse over 3 outputs to distinguish between the 3 curves, when legend descriptor arrows appear:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.