0
$\begingroup$

My data file can be found here: data

data = Import["mnl.out", "Table"];

First we remove the headers

l0 = SplitBy[data, Dimensions][[2 ;; ;; 2]]

and then we plot it

L1 = ListPlot[l0, Frame -> True, Axes -> False, PlotStyle -> {Red}, 
 Joined -> True, PlotRange -> {{6., 13}, {-0.9, 2.4}}]

enter image description here

Now I want to create a new list l1 (with the same structure as l0) so as the corresponding plot (in green) to be mirror-symmetrical with respect to the y = 0 axis.

Any suggestions?

Many thanks in advance!

$\endgroup$
1
  • $\begingroup$ Related: (38138) $\endgroup$
    – Mr.Wizard
    Sep 27, 2015 at 9:27

3 Answers 3

8
$\begingroup$

I feel like I must be missing something but this seems to answer your question:

new = Map[{1, -1} # &, l0, {-2}];

ListLinePlot[new, Frame -> True, Axes -> False, PlotStyle -> Green, 
 PlotRange -> {{6., 13}, {-2.4, 0.9}}]

enter image description here

Since it seems that this is indeed what you want here is a faster but to me more opaque method using Dot:

new2 = l0.{{1, 0}, {0, -1}};

new == new2   (* True *)
$\endgroup$
4
  • $\begingroup$ It works like a charm! I tried l1 = Table[{l0[[i, j]][[1]], -l0[[i, j]][[2]]}, {i, 1, Length[l0]}, {j, 1, Length[l0]}] but the new list has less points. Any idea why? $\endgroup$
    – Vaggelis_Z
    Sep 27, 2015 at 9:05
  • 1
    $\begingroup$ @Vaggelis_Z You would need to change the second iterator to {j, 1, Length @ First @ l0}. $\endgroup$
    – Mr.Wizard
    Sep 27, 2015 at 9:23
  • 1
    $\begingroup$ "more opaque" - unless you go with the "matrix multiplication" viewpoint. Then, a diagonal matrix is easily interpreted as a scaling transform. Here's the equivalent, but maybe cognitively less demanding version: ScalingTransform[{1, -1}] /@ l0. $\endgroup$ Oct 8, 2015 at 12:42
  • $\begingroup$ @J.M. Good to have you back! :-) I am not surprised the dot operation is transparent to you but I have yet to reach that level of familiarity with matrix operations. $\endgroup$
    – Mr.Wizard
    Oct 8, 2015 at 17:48
5
$\begingroup$

Just for trivial variety illustrating MapAt and using dummy data (as well as my original version which is not meaningfully different from Mr Wizard: whose answer I have upvoted):

dat = MapIndexed[{#2[[1]], #1} &, #] & /@ RandomReal[1, {3, 10}];
f = {1, -1} # &
ListPlot[Map[f, dat, {2}]~Join~dat, Joined -> True, 
 PlotStyle -> {Red, Green, Blue}]

now using MapAt:

ListPlot[MapAt[-# &, dat, {All, All, 2}]~Join~dat, Joined -> True, 
 PlotStyle -> {Red, Green, Blue}]

enter image description here

$\endgroup$
0
3
$\begingroup$
reflectF = GeometricTransformation[#, ReflectionTransform[{0, -1}]] &;

Show[L1, L1 /. l_Line :> {Green, reflectF @ l}, PlotRange -> {{6., 13}, All}]

enter image description here

l1 = ReflectionTransform[{0, -1}] /@ l0;
ListPlot[l1, PlotStyle -> {Green}, Joined -> True, PlotRange -> {{6., 13}, {-2.4, 0.9}}]

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.