1
$\begingroup$

If I have the following:

Show[data1, data2, data3,PlotRange -> {All, All}]

where data1, data2 and data3 are of the form Plot[g, {x, 0, 100},ImageSize->Large,....etc.]

How can I shift the data that I see in Show for data1, data2 and data3 without modifying the g of the data itself?

I was trying something like this, in order to shift the y axis of the plot stored in data1 by 0.1, the plot stored in data2 by 0.2 and the plot stored in data3 by 0.3:

Show[data1/. {x_, y_} -> {x, y+0.1}, data2/. {x_, y_} -> {x, y+0.2}, data3/. {x_, y_} -> {x, y+0.1},PlotRange -> {All, All}]

I know that the easiest way is simply to use /. {x_, y_} -> {x, y+0.1} in the individual data but I was wondering if it is possible to do like this?

$\endgroup$

2 Answers 2

2
$\begingroup$

Maybe Translate?:

p1 = p2 = p3 = Plot[Sin[x], {x, 0, 2 Pi}]

Show[
 MapAt[Translate[#, {0, 0.1}] &, p1, 1],
 MapAt[Translate[#, {0, 0.2}] &, p2, 1],
 MapAt[Translate[#, {0, 0.3}] &, p3, 1],
 PlotRange -> All
 ]

enter image description here

$\endgroup$
5
  • $\begingroup$ Michael, one question. I am trying the same for plots with ListLinePlot rather than Plot and it doesn't seem to work for ListLinePlot. Is there something I can modify to make it work with ListLinePlot? $\endgroup$
    – John
    Commented Jan 13, 2021 at 17:00
  • 1
    $\begingroup$ @John The above works for me if I change the plot to p1 = p2 = p3 = ListLinePlot[Sin[N@Range[100]/17]]. It does not work for some other one? $\endgroup$
    – Michael E2
    Commented Jan 13, 2021 at 17:48
  • $\begingroup$ You are right, I was doing something incorrectly in my code. Also, is there any way to input rotation in your code? It only moves the curves up or down, correct?. Is there an easy modification to include rotation as well?. In other words, to have both translation and rotation. $\endgroup$
    – John
    Commented Jan 13, 2021 at 22:28
  • $\begingroup$ Michael E2, I plotted the question here as well: mathematica.stackexchange.com/questions/238184/… $\endgroup$
    – John
    Commented Jan 13, 2021 at 22:41
  • 1
    $\begingroup$ There's Rotate. Just compose them. Rotate[Translate[#, {0, 0.2}], 5 Degree] & or vice versa. There's also GeometricTransformation for general affine transformations of graphics. FindGeometricTransform can be used to find the affine transformation that aligns points as well as possible. $\endgroup$
    – Michael E2
    Commented Jan 13, 2021 at 22:43
1
$\begingroup$
plot = Plot[2 x^2, {x, -2, 3}];
shifted = plot /. Line[l_List] :> {Red, Line[{#1, #2 + 3} & @@@ l]};
Show[{plot, shifted}]

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.