I have a list of data {{x1,c11}, {x1,c12}, {x2,c21},{x2,c22}, {x3,c31},{x3,c32}, {x4,c4}, {x5,c51},{x5,c52}, ...}
, in which x
is real value and c
is complex value. For some x
, there is only a c
value, for example, {x4,c4}
pair, while for the most x
there are a pair of distinct c
, e.g. {x2,c21},{x2,c22}
.
I want to plot x
versus the real and imaginary parts of c
, respectively, and render the x
-Re[c]
and x
-Im[c]
curves with a same color for the associated Re[c]
and Im[c]
. In other words, in both x
-Re[c]
and x
-Im[c]
plots, there will be two curves, I need to show the 4 curves in two different colors with the same color means the values of Re[c]
and Im[c]
are from the same c
.
For example, c21=Re[c21]+i*Im[c21]
and c22=Re[c22]+i*Im[c22]
, the points {x2,Re[c21]}
and {x2,Im[c21]}
should be in a color, while the points {x2,Re[c22]}
and {x2,Im[c22]}
should use another color.
The key point of the question could be how to separate the interleaved data, in which most values of x
have a pair of k
but with some exceptions. I need a general method to handle such data with the above-mentioned features. Thank you very much!
Here is the sample data for testing.
test = ToExpression /@ Import["Documents\\testdata.csv"];
xci = test /. {x_, c_} -> {x, Im[c]};
xcr = test /. {x_, c_} -> {x, Re[c]};
{ListPlot[xci, PlotStyle -> Blue, PlotRange -> All, Frame -> True],
ListPlot[xcr, PlotStyle -> Red, PlotRange -> All, Frame -> True]}
Update: The problem can be converted to plot two curves in 3D with different colors. As can be seen, the two curves are well separated in the {Re[c], Im[c], x}
space, thus this way might be easier.
xc3D = test /. {x_, c_} -> {Re[c], Im[c], x};
ListPointPlot3D[xc3D, PlotStyle -> Red, AxesLabel -> {cr, ci, x}]