Message Boards Message Boards


Reverse axis with Show option

Posted 6 years ago
9 Replies
1 Total Likes

Hey, I am new on Mathematica and I have some trouble with basic functions. I want to make a graph with points, lines and names/arrows. I was able to do it using Show and binding several functions. However, I need to reverse the axis and for that if I used ScalingFunctions, the names disappear on my graph (-> pictures) Somebody have any idea how to do it?

Thank you

POSTED BY: Christophe Nell
9 Replies

Something like this?

Show[ListLinePlot[{{{1, 5}, {4, 8}}}, ScalingFunctions -> {Identity, "Reverse"}], Graphics[Text["My Name here", {2, -7}, {0, 0}]]]

enter image description here

You can, of course, get the same thing without Show:

ListLinePlot[{{{1, 5}, {4, 8}}}, ScalingFunctions -> {Identity, "Reverse"}, Epilog -> Text["My Name here", {2, -7}, {0, 0}]]



POSTED BY: Marco Thiel

Hey, in fact, the problem is that the Y-value for the text is not the same than the Y-axis. With your solution, it is at -7 and not 7 as in the graph. I need to add vectors and different stuffs on my graph, so to have this change of value is really not good...

POSTED BY: Christophe Nell

Nobody has any idea how to reverse the Y-axis but keep the good coordinate for the label?

POSTED BY: Christophe Nell

There is no good construct at the moment unfortunately... you would have to make lots of rules for each kind of 'primitive': Text,Line,Polygon, Point, ... et cetera...

POSTED BY: Sander Huisman

Actually there is Sander, if only graphics were organized around graphics primitives instead of everything top down. Here is an example with the ListLinePlot, circle points, Text, a circle and a rectangle all specified in normal coordinates.

It uses the Presentations application, which I used to sell. I use a postfix ReflectionTransform to reflect everything and a CustomTicks routine to rescale the y axis. The only glitch is that Wolfram not only reflects the position of the Text but also the characters. To me this is bad design. I don't understand why anyone would want to do that. In any case, it can be compensated by a pre-reflection.

<< Presentations` 
yticks = CustomTicks[Rescale[#, {5, 8}, -{5, 8}] &, {5, 8, 1, 5}];
 {{ListLineDraw[{{{1, 5}, {4, 8}}}],
    Text["My Name here", {2, 7}] // 
     ReflectionTransformOp[{0, -1}, {2, 7}],
    CirclePoint[#, 3, Black, Orange] & /@ {{1, 5}, {4, 8}},
    Circle[{2, 7}, 0.5],
    EdgeForm[Black], FaceForm[Orange], 
    Rectangle[{2.5, 5.4}, {4.0, 4.8}]} // 
   ReflectionTransformOp[{0, -1}, {0, 0}]
 PlotRangePadding -> 0.2,
 Frame -> True,
 FrameTicks -> {{yticks, yticks // NoTickLabels}, {Automatic, 

The resulting graphic:

enter image description here

Actually there is Sander, if only graphics were organized...

So there isn't really... as I said... There is no good construct without doing some hacks, use packages, or other kinds of tricks..

Of course I was thinking about doing a reflection around a certain coordinate. Though that works fine with polygons and lines and some other things, it does not work with text and others, so you need rules like this:

/. Text[txt_,a_,b___] :> Text[txt,a{1,-1},b]

to convert those. But also for Insets of arbitrary stuff you might not want to reflect the contents of the reflected stuff (like a custom legend), but you do want to convert the pos and opos of Inset[....pos, opos] accordingly. All those fringe-cases makes it quite tricky to do.

My bet is that he uses a very much simplified version of his real problem, as I guess he doesn't want "My name here" in his plot...To cover all bases you need to do quite some work...

POSTED BY: Sander Huisman

Of course it wouldn't be a hack or a trick if WRI organized the user perspective of graphics from graphics primitives up instead of from set-piece plots down.

I showed you a simple way it could be done - and you didn't like it.

Are you suggesting that third party packages (better called applications) are equivalent to "hacks" and "tricks"? Mathematica has a lot of nice things and nice design in it - but there are also areas of bad design and the graphics paradigm is one of them.

Is it "The Wolfram way or the highway?" How successful would the iPhone be if Apple only allowed Apple written code on the device?

What I meant is, is that in your solutions you reflect every piece yourself. Which is ok for 2 items. But what if I have a 100 items? Then your method becomes very tedious...

But if you do it with rules, as I said above, it can become much cleaner, easier, and much easier expandable to any number of items. And it fits into the built-in plot-functions and the 'graphics paradigm'...

Also, your solution is much more convoluted than the one from Marco Thiel... If you have to do it manually, then I favour his, much easier to 'read'.

A general approach would be to use a reflection-transform for most things, and a few special cases for things like text... Which will work without any package, should be quite small, and would work for most if not all cases...

POSTED BY: Sander Huisman

Hey guys, thank you for all these details. Indeed, I need to plot multiple stuffs in my graph, such as vector, angles, line-points-text. Because of that, it is a bit tricky to reverse the y-coordinate by hand on every object. It is especially true for vector as I'd rather to use them without splitting x-y values.

My code, for the moment looks like:

     posLEwithFKF[[2]]}, {posMEwithFKF[[1]], 
     posMEwithFKF[[2]]}}, { {posPLCwithFKF[[1]], 
     posPLCwithFKF[[2]]}, {posPMCwithFKF[[1]], 
     posPMCwithFKF[[2]]}}, {{posMTEAwithFKF[[1]], 
  PlotRange -> {{Min[posLEwithFKF[[1]], posMEwithFKF[[1]]] - 20, 
     Max[posLEwithFKF[[1]], posMEwithFKF[[1]]] + 
      20}, {Max[posPMCwithFKF[[2]], posPLCwithFKF[[2]], 
       posLEwithFKF[[2]]] + 20, 
     Min[posPMCwithFKF[[2]], posPLCwithFKF[[2]], posLEwithFKF[[2]]] - 
   Frame -> {{True, False}, {True, False}}, 
  FrameLabel -> {"X\!\(\*SubscriptBox[\(\\\ \), \(FKF\)]\)", 
    "Y\!\(\*SubscriptBox[\(\\\ \), \(FKF\)]\)"}, Mesh -> Full, 
  MeshStyle -> Directive[PointSize[Large], Red]],

  Text["LE", {posLEwithFKF[[1]], posLEwithFKF[[2]]}, {-1.5, -1}]], 
   "MTEA", {posMTEAwithFKF[[1]], posMTEAwithFKF[[2]]}, {-1.5, -1}]], 
   "ME", {posMEwithFKF[[1]], posMEwithFKF[[2]]}, {-1, -1}]], 
  Text["Proj C.P PLC", {posPLCwithFKF[[1]], 
    posPLCwithFKF[[2]]}, {-1, -1}]], 
   "Proj C.P PMC", {posPMCwithFKF[[1]], 
    posPMCwithFKF[[2]]}, {-1, -1}]],

     posMTEAwithFKF[[2]]}, {posMTEAwithFKF[[1]], 
      posMTEAwithFKF[[2]]} + vectorTEAforAlphapost/4}]], 
     posMTEAwithFKF[[2]]}, {posMTEAwithFKF[[1]], 
      posMTEAwithFKF[[2]]} + vectorPLCtoPMCinFKFinXY/2}]],
 Graphics[Text[Style["Alpha post", Green],
   {posMTEAwithFKF[[1]] + vectorPLCtoPMCinFKFinXY[[1]]/4 , 
    posMTEAwithFKF[[2]] + vectorTEAforAlphapost[[2]]/8}

And I want to reverse only the Y-axis with a simple command if possible. But if I have to do it for every object, I'd better to let it like this and put a comment how to read the graph!

POSTED BY: Christophe Nell
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract