Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: ListPlot, Inverse plotting

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90678] Re: ListPlot, Inverse plotting
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 19 Jul 2008 04:48:34 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g5pivh$qav$1@smc.vnet.net>

Richard Trilling wrote:

> I want to do a standard ListPlot but I would like to inverse the x-axis 
> values such that the maximum is to the left of the minimum.
> 
> Is there an easy way to do that with the options of ListPlot?

No.

However, you may manipulate and transform the graph as you would do with 
any other Mathematica expression. You can see the expression thanks to 
FullForm[]. Also, note that the option Joined set to True changes the 
Point graphic directive to Line, and that the same idea of manipulating 
the graph expression works if you had a Plot rather than a ListPlot. 
Below are some examples -- not optimized for anything since the real 
expressions depends on your actual code/plot/data.

     xmin = -2; xmax = 4;
     data = Table[{x, E^x}, {x, xmin, xmax, (xmax - xmin)/100}];
     g = ListPlot[data, PlotRange -> {{xmin, xmax}, Automatic},
       Ticks -> {Table[{n, n}, {n, xmin, xmax}], Automatic}]
     FullForm[g]
     Show[g /. l_Point :> (l /. {x_?NumberQ, y_?NumberQ} -> {-x, y}),
       PlotRange -> {{-xmax, -xmin}, Automatic},
       Ticks -> {Table[{n, -n}, {n, -xmax, -xmin}], Automatic}]

     g = ListPlot[data, Joined -> True,
       PlotRange -> {{xmin, xmax}, Automatic},
       Ticks -> {Table[{n, n}, {n, xmin, xmax}], Automatic}]
     FullForm[g]
     Show[g /. l_Line :> (l /. {x_?NumberQ, y_?NumberQ} -> {-x, y}),
       PlotRange -> {{-xmax, -xmin}, Automatic},
       Ticks -> {Table[{n, -n}, {n, -xmax, -xmin}], Automatic}]

     g = Plot[E^x, {x, xmin, xmax}, PlotRange -> {{xmin, xmax},
       Automatic}, Ticks -> {Table[{n, n}, {n, xmin, xmax}], Automatic}]
     FullForm[g]
     Show[g /. l_Line :> (l /. {x_?NumberQ, y_?NumberQ} -> {-x, y}),
     PlotRange -> {{-xmax, -xmin}, Automatic},
       Ticks -> {Table[{n, -n}, {n, -xmax, -xmin}], Automatic}]


Regards,
-- Jean-Marc



  • Prev by Date: Re: Labeled Plot not a Plot?
  • Next by Date: Re: Collapsing cell groups [was: Mathematica
  • Previous by thread: Re: ListPlot, Inverse plotting
  • Next by thread: Re: ListPlot, Inverse plotting