2
$\begingroup$

I have four data sets in the form {f(x),x} as, data1, data2, data3, data4.

Now, I am trying to plot the four datasets using ListLinePlot. But I'm not able to get the desired result

    ListPlot[{data1, data2, data3, data4}, AxesOrigin -> {0, 0},PlotStyle -> {Red,Blue,Orange,Brown}, 
    PlotTheme -> "Detailed", LabelStyle -> Directive[Large, Plain, 24], 
    Frame -> {{True, False}, {True, False}}, 
    FrameLabel -> {Style["x", 24, Plain, Black], 
    Style["f(x)", 24, Plain, Black]}, ImageSize -> {850, 550}, 
    InterpolationOrder -> 2]

enter image description here

I wanted some of the curves to be dashed and some dotted, tried using Directive, didn't know how to make it work.
Is there a way to show PlotExpression (I tried it as well, didn't work), for e.g. red curve means Δ = 0. Similarly, blue means Δ = -0.5, brown means Δ = +0.5, yellow means Δ =+1. Kind of a research paper style on the right side of the figure?
Even AxesOrigin didn't work here, I wanted to be at {0,0}? Surely, I'm missing something.

$\endgroup$
8
  • $\begingroup$ Include Dashed , Dotted inside PlotStyle: PlotStyle -> {{Dashed,Red},{Dotted,Blue},Orange,Brown} $\endgroup$ Jul 3, 2019 at 9:02
  • $\begingroup$ for legends try PlotLegends -> {"\[CapitalDelta] = 0", "\[CapitalDelta] = -0.5", "\[CapitalDelta] = 0.5", "\[CapitalDelta] = 1.0" } $\endgroup$
    – kglr
    Jul 3, 2019 at 9:04
  • $\begingroup$ @UlrichNeumann I think, PlotStyle is not working, because these are not smooth curves but data points maybe? $\endgroup$
    – Shamina
    Jul 3, 2019 at 9:06
  • $\begingroup$ @kglr Thanks! It works. Just a naive question. Instead of color dot then Legend. Can we have a thick color strip instead of a dot? dot is just too small $\endgroup$
    – Shamina
    Jul 3, 2019 at 9:07
  • $\begingroup$ try PlotLegends ->LineLegend[ {"\[CapitalDelta] = 0", "\[CapitalDelta] = -0.5", "\[CapitalDelta] = 0.5", "\[CapitalDelta] = 1.0" }] $\endgroup$
    – kglr
    Jul 3, 2019 at 9:16

1 Answer 1

2
$\begingroup$

We separate each data set into several paths using FindCurvePath followed by manual adjustments:

{data1a, data1b} = data1[[#]] & /@ FindCurvePath[data1];
{data2a , data2b} = GatherBy[data2[[FindCurvePath[data2][[1]]]], #[[2]] <= -1 &];
{data3a, data3b, data3c} = data3[[#]] & /@ FindCurvePath[data3];
{data4a, data4b} = data4[[#]] & /@ FindCurvePath[data4];
data4a = Rest @ data4a;
data3a = data3a[[4 ;;]];

Then we use ListLinePlot with input {data1a, data1b, data2a, data2b, data3a, data3b, data3c, data4a, data4b} and specify the list of styles so that parts corresponding to each data set has the same styles:

ListLinePlot[{data1a, data1b, data2a, data2b, data3a, data3b, data3c, data4a, data4b}, 
 AxesOrigin -> {0, 0}, 
 PlotStyle -> {Red, Red, Directive[Thick, Blue, Dashed], Directive[Thick, Blue, Dashed], 
    Orange, Orange, Orange, Brown, Brown}, 
 LabelStyle -> Directive[Large, Plain, 24], 
 Frame -> {{True, False}, {True, False}}, 
 FrameLabel -> {Style["x", 24, Plain, Black], 
   Style["f(x)", 24, Plain, Black]}, ImageSize -> {850, 550}, 
 PlotLegends -> LineLegend[{Red, Directive[Thick, Blue, Dashed], Orange, 
    Brown}, {"Δ = 0", "Δ = -0.5", "Δ = 0.5", "Δ = 1.0"}]]

enter image description here

If you don't mind the vertical and horizontal lines, you can simply use ListCurvePathPlot without any additional processing:

ListCurvePathPlot[{data1, data2, data3, data4}, AxesOrigin -> {0, 0}, 
 PlotStyle -> {Red, Blue, Orange, Brown}, 
 LabelStyle -> Directive[Large, Plain, 24], 
 Frame -> {{True, False}, {True, False}}, 
 FrameLabel -> {Style["x", 24, Plain, Black], 
   Style["f(x)", 24, Plain, Black]}, ImageSize -> {850, 550}]

enter image description here

$\endgroup$

Your Answer

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

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