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?
Thanks.
Transform the x-scale. For instance, define
W[x_] := If[x < .5, x, .5 + (x-.5)/9]
then plot using
ListPlot[{W@#[[1]],#[[2]]}&/@t,
Ticks->{{W@#,#}&/@{.25,.5,2,3,4,5},Automatic}]
For more general situations, consider "nicer" functions such as
With[{c = 9}, ListPlot[{ArcSinh[c*#[[1]]],#[[2]]}&/@t,
Ticks->{{ArcSinh[c*#],#}&/@{.1,.2,.5,1,2,3,4,5},Automatic}]]
with the parameter (in this case, c) and the list of tick values
adjusted to taste.
>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?
There are a number of ways that should achieve something
suitable. Based on my interpretation of what you are asking for,
I suggest the following:
func = Piecewise[{{Sin[100 x], x < .5}, {Sin[x], x >= .5}}];
GraphicsRow[{Plot[func, {x, 0, .5},
Frame -> {True, True, False, False}, Axes -> None],
Plot[func, {x, .5, 5}, Frame -> {True, False, False, False},
Axes -> None]}, Spacings -> 0]
I've used Piecewise rather than creating a list of data points
to apply since that allows me to take advantage of Mathematica's
adaptive sampling algorithm. I see no point to explicitly
computing values and using ListPlot if the only purpose is to
produce a graphic.
Literally, have created two separate plots and use GraphicsRow
to combine them in an appropriate fashion to make a single
graphic. The net effect is a single graphic with a break in the x-axis.
This particular approach does introduce one aspect in the final
graphic that could be seen as misleading. As the function is
defined, there start of the graph on the right hand side should
appear directly above the end of the graph on the left hand side
rather than being displaced along the horizontal axis.
But given the scaling changes, it isn't clear to me making the
start of the right graphic align vertically with the end of the
left graphic is any less misleading.
t1 = Select[t, First[#] < 0.5 &];
t2 = Complement[t, t1];
Grid[{{
ListLinePlot[t1,
ImageSize -> 250,
Axes -> {True, False},
Frame -> {True, True, True, False},
PlotRange -> {{-0.01, 0.5}, {-1.05, 1.05}},
PlotStyle -> Blue],
ListLinePlot[t2,
ImageSize -> 220,
Axes -> {True, False},
Frame -> {True, False, True, True},
PlotRange -> {{0.5, 5.1}, {-1.05, 1.05}},
PlotStyle -> Directive[Thick, Magenta]]}},
Spacings -> -0.25]
Bob Hanlon
---- Nacho <ncc17...@gmail.com> 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?
Thanks.
--
Bob Hanlon
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).
foo[x_?NumericQ] := If[x < .5, Sin[100*x], Sin[x]]
GraphicsRow[
{Plot[foo[x], {x, 0, 0.5}],
Plot[foo[x], {x, 0.5, 5}, Axes -> {True, False}]},
Spacings -> {-10.0, 0}]
??
Regards
Jens
Not exactly a piecewise axis but the function *ListLogLinearPlot* should
produce something close enough to what you have in mind.
t = Table[{x, If[x < .5, Sin[100*x], Sin[x]]}, {x, 0, 5, 0.001}];
ListPlot[t]
ListLogLinearPlot[t]
Regards,
-- Jean-Marc
You could certainly draw the graphic you want if you spend a lot of
time building it from scratch with graphics primitives -- I suggest
you start by drawing the x-axis you want with Lines.You might be able
to get close to what you want by experimenting with GraphicsGrid. In
either case you risk creating a graphic with a misleading x - axis, so
don' t forget to put some indication of the break of scale at x ==
0.5.
Or, you could use ListLogLinearPlot[t] and get close to what you are
asking for with no fuss or tricky programming, and get on with your
work.
Regards
Mark Westwood
Re: How can I create a two-axis graph in Mathematica v6
You might check this out. I highly recommend his package.
Kevin
--
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
"Szabolcs Horv=E1t" <szho...@gmail.com> wrote in message
news:gcffqv$f62$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 p=
lot
>> 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 tha=
t
I always thought that @ had a higher precedence than [[ ]]
But it looks like [[ ]] has the same precedence as [ ].
I think I'll adopt the solution from Szabolcs Horvat, I really like
the results and the approach.
Best regards.