Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Flipping axes on Graphics

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97417] Re: Flipping axes on Graphics
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Fri, 13 Mar 2009 04:46:39 -0500 (EST)
  • References: <gpad36$n1p$1@smc.vnet.net>

sidney at jigsaw.nl wrote:
> Dear all,
> 
> I am looking for a way to flip the direction of an axis that is used
> to render a Graphics object.
> 
> For example, I would like to be able to do Plot[Sin[x], {x, 0, 2*Pi}]
> but the top-left corner of the rendered Graphics object would
> correspond to coordinate (0,-1) while the bottom-left corner would
> correspond to (0, +1); effectively, the graph would need to be
> mirrored in the x-axis.
> 
> I've skimmed all Graphics options and it seems the convention that
> increasing x is rendered left-to-right and increasing y is rendered
> bottom-to-top is hard-wired into Graphics. Would there be a clever way
> to get around this?
> 

Just flip the function, then relabel the axes.  Here's an example:

f[x_] := Sin[x] + x^2/10

Plot[f[x], {x, -5, 5}]

gr = Plot[f[-x], {x, -5, 5}]

invertXTicks[gr_Graphics] := Module[{xticks, yticks},
   {xticks, yticks} = FullOptions[gr, Ticks];
   {Replace[
     xticks,
     {position_, label_Real, rest__} :> {position, -label, rest}, {1}],
    yticks}
   ]

Show[gr, Ticks -> invertXTicks[gr]]


  • Prev by Date: Re: General form of a summation as a function of 2
  • Next by Date: Re: Wolfram/Alpha (Wikipedia page restored)
  • Previous by thread: Re: Flipping axes on Graphics
  • Next by thread: Re: Flipping axes on Graphics