Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a relatively simple operation I'd like to perform on a plot: I would like to reflect the plot across the x-axis. I do not have any tick labels, so making sure that the labels are not themselves reflected is not a concern.

Rotating the plot works as expected:

Rotate[ListPlot[{{0,0},{1,1}},Joined->True],90\[Degree]]

...but there does not appear to be a "Reflect" command or equivalent that performs a reflection operation. I've tried using GeometricTransformation and Scale, but both of those don't seem to work on plot objects. How should I go about doing this?

share|improve this question
1  
Can't you just change all y values into -y? Just do {#[[1]],-#[[2]]}& /@ pointList, with pointList the set of points to be plotted. –  Sjoerd C. de Vries Jul 3 '12 at 22:21
    
I have filling in my plot, and I'm also doing a rotation (essentially I'm flipping about the y = x axis), so while what you suggest would work for the simple example I provided, it doesn't work in general for more complicated operations. –  Guillochon Jul 3 '12 at 22:24
    
If you only need to flip a 2D image, then you can use ImageReflect –  rm -rf Jul 4 '12 at 2:36
add comment

4 Answers 4

up vote 12 down vote accepted

How about something like this (example shamelessly stolen from the docs)

f[n_, x_] := 
 Abs[((1/Pi)^(1/4) HermiteH[n, x])/(E^(x^2/2) Sqrt[2^n n!])]^2
lp = Plot[Evaluate@
     Append[Table[f[n, x] + n + 1/2, {n, 0, 7}], x^2/2], {x, 0, 4}, 
  Filling -> Table[n -> n - 1/2, {n, 1, 8}]]

Graphics[FullGraphics[
    lp][[1]] /. {x_Real, 
    y_Real} :> {-x, y}, 
    AspectRatio -> .42*2.380952380952381]

Mathematica graphics

(you said ticks aren't important so I ignored them). This is similar to Sjoerd's suggestion in the comments but for the whole plot.

share|improve this answer
add comment

Few examples from the docs on ReflectionTransform used in combination with GeometricTransformation

  gr = Plot[ E^x, {x, -3, 2}]; 
  Row[{Show[gr, Plot[x, {x, -3, 7}, PlotStyle -> Black], 
   gr /. L_Line :> {Red, GeometricTransformation[L, ReflectionTransform[{-1, 1}]]}, 
   PlotRange -> All, ImageSize -> 200], 
   Show[gr, gr /. L_Line :> {Red, GeometricTransformation[L, ReflectionTransform[{-1, 0}]]}, PlotRange -> All, ImageSize -> 200], 
  Show[gr, gr /. L_Line :> {Red, GeometricTransformation[L, ReflectionTransform[{0, -1}]]}, PlotRange -> All, ImageSize -> 200]}, Spacer[15]]

enter image description here

 cow = ExampleData[{"Geometry3D", "Cow"}, "GraphicsComplex"];
 p1 = {0, 0, -0.25161901116371155`};
 p2 = {0, 0, 0.25161901116371155`};
 Row[{Graphics3D[{EdgeForm[None], Opacity[0.5], 
 Lighter[ColorData[1, 1], 0.5], cow, Lighter[ColorData[1, 2], 0.5], 
 GeometricTransformation[cow, #]}, Lighting -> "Neutral", 
 ImageSize -> Small, Boxed -> False] & /@
{ReflectionTransform[{0, 0, 1}, p1], 
 ReflectionTransform[{0, 0, 1}, p2],
 ReflectionTransform[{1, 0, 0}, p1], 
 ReflectionTransform[{1, 1, 0}, p1]}}, Spacer[15]]

enter image description here

share|improve this answer
1  
wish I could upvote again for the cows –  acl Jul 3 '12 at 23:19
    
Holy Flying Cows, Batman! –  belisarius Jul 4 '12 at 4:48
    
can this be made to flip the axes? –  acl Jul 4 '12 at 10:13
1  
+1 There should be more answers on this site involving semi-transparent cows. –  Simon Woods Jul 4 '12 at 11:21
    
@acl, @belisarius, @Simon, thanks for the votes. ReflectionTransform seemed gentle and safe .. but getting carried away with variations of examples featuring cows and transforms could expose one to animal cruelty charges (e.g. ShearingTransform). Simon, perhaps a semi-transparent cows blog:)? –  kguler Jul 4 '12 at 21:01
add comment

You can actually use Scale for this by doing something like

MapAt[Scale[#, {-1, 1}] &, Plot[Sin[x], {x, 0, 2 Pi}] , {1}]

Mathematica graphics

share|improve this answer
add comment

There is a very simple way to "mirror" a function in the y-axis.

Just write $f[-x]$, where you need.

Example:

f[x_] = 2 x - 3;
Plot[Which[x > 0, f[x], x < 0, f[-x]], {x, -5, 5}, PlotRange -> All]

mirror in y-axis

To mirror a function in the x-axis you can place $-f[x]$, where you need.

Example:

f[x_] = 2 x - 3;
P1 =  Plot[f[x], {x, -5, 5}, PlotRange -> All];
P2 =  Plot[-f[x], {x, -5, 5}, PlotRange -> All, PlotStyle -> Red];
Show[P1, P2]

mirror in x-axis

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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