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

MathGroup Archive 2008

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

Search the Archive

Re: Axis in two scales

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92592] Re: Axis in two scales
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Tue, 7 Oct 2008 07:05:36 -0400 (EDT)
  • Organization: University of Bergen
  • References: <gcchas$s1q$1@smc.vnet.net>

Nacho wrote:
> Hello everyone.
> 
> I have a dataset in pairs (x,y) that I would like to plot. The main
> problem is that the data set has interesting parts in the beginning
> that I would like to view clearly.
> 
> As an example, create the following table:
> 
> t = Table[{x, If[x < .5, Sin[100*x], Sin[x]]}, {x, 0, 5, 0.001}];
> ListPlot[t]
> 
> You have a very detailed sine in the beginnng and the rest is less
> interesting.
> 
> I would like to "split" the X axis in two, so the left half of the
> plot covers x={0,0.5} and the second half x={0.5,5}] in the same plot
> and with the right ticks.
> 
> It is like a piecewise axis... is it possible?
> 

You can use custom tick marks, take a look at Ticks and FrameTicks.

Here's a way to do it:

First we define a function to transform x coordinates:

trafo = \[Piecewise] {
     {#, # <= 0.5},
     {Rescale[#, {0.5, 5}, {0.5, 1}], # > 0.5}
    } &

In our case this is just a piecewise linear rescaling.

Then apply this function to x coordinates and to the tick positions that 
we wish to show:

ListPlot[
  {trafo[#1], #2} & @@@ t,
  Ticks ->
    {{trafo[#], #} & /@ Join[Range[0, 0.5, 0.1], Range[1, 5]],
     Automatic}
]

The advantage of this approach is that it is easily generalized: we 
could have used trafo = #^(1/3) & for a fancy non-linear scaling, or 
just trafo = Log to mimic ListLogLinearPlot (better not try to put a 
tick mark at 0 in this case).



  • Prev by Date: Re: Real and Complex Roots presented in a single plot
  • Next by Date: Re: integration
  • Previous by thread: Re: Axis in two scales
  • Next by thread: Re: Axis in two scales