From: Mather on
Hi,guys
I want to plot with a reversed Y-axis, that is to say, along the Y-
axis direction the numbers become smaller.
For example:

ListLinePlot[Table[{i, i^2}, {i, {1, 2, 3, 4, 5, 6}}],
PlotRange -> {{0, 8}, {50, 0}}]

However it does not work.
Can anybody help with this?

Thanks in advance!

From: David Park on
Needs["Presentations`Master`"]

yticks = CustomTicks[-# + 50 &, {0, 50, 10, 5}];
Draw2D[
{ListLineDraw[Table[{i, i^2}, {i, {1, 2, 3, 4, 5, 6}}]] /.
DrawingTransform[#1 &, -#2 + 50 &]},
AspectRatio -> 0.63,
Frame -> True,
FrameTicks -> {{yticks, yticks // NoTickLabels}, {Automatic,
Automatic}},
PlotRange -> {{0, 8}, {0, 50}},
PlotRangePadding -> {0.1, 1},
PlotLabel -> "Reverse y Axis Plot"]


David Park
djmpark(a)comcast.net
http://home.comcast.net/~djmpark/



From: Mather [mailto:sdzbbjhd(a)hotmail.com]

Hi,guys
I want to plot with a reversed Y-axis, that is to say, along the Y-
axis direction the numbers become smaller.
For example:

ListLinePlot[Table[{i, i^2}, {i, {1, 2, 3, 4, 5, 6}}],
PlotRange -> {{0, 8}, {50, 0}}]

However it does not work.
Can anybody help with this?

Thanks in advance!



From: Armand Tamzarian on
On Sep 25, 4:58 am, Mather <sdzbb...(a)hotmail.com> wrote:
> Hi,guys
> I want to plot with a reversed Y-axis, that is to say, along the Y-
> axis direction the numbers become smaller.
> For example:
>
> ListLinePlot[Table[{i, i^2}, {i, {1, 2, 3, 4, 5, 6}}],
> PlotRange -> {{0, 8}, {50, 0}}]
>
> However it does not work.
> Can anybody help with this?
>
> Thanks in advance!


Clear[ReverseListPlot];

ReverseListPlot::usage =
"ReverseListPlot[{list1, list2, \[Ellipsis]}, options] will \
generate a ListLinePlot with the \!\(\*FormBox[\"x\",
TraditionalForm]\), \!\(\*FormBox[\"y\",
TraditionalForm]\), or both \!\(\*FormBox[\"x\",
TraditionalForm]\) and \!\(\*FormBox[\"y\",
TraditionalForm]\), axes reversed. ReverseAxis \[Rule] \"X\", \
ReverseAxis \[Rule] \"Y\", ReverseAxis \[Rule] \"XY\" are specific \
options. Other options are the same as for ListLinePlot.";

SyntaxInformation[
ReverseListPlot] = {"ArgumentsPattern" -> {_, OptionsPattern[]}};

Options[ReverseListPlot] =
Join[Options[ListLinePlot], {ReverseAxis -> "X"}];

ReverseListPlot[data__List, opts : OptionsPattern[]] :=
Module[{p1, frameticks, grids, ticks, opts1, reverseOpts, data1,
newXGrids, newYGrids, newXTicks, newXBottomTicks, newXTopTicks,
newYTicks, newYLeftTicks, newYRightTicks},

(* make framed plot otherwise make axes plot.
If Axes and Frame are both True no Ticks are produced in \
ListLinePlot--only FrameTicks are produced,
so need to produce these separately *)

If[OptionValue[Frame] == True,
p1 = ListLinePlot[data, Axes -> False, Frame -> True,
GridLines -> OptionValue[GridLines],
FrameTicks -> OptionValue[FrameTicks],
FrameTicksStyle -> OptionValue[FrameTicksStyle],
PlotRange -> OptionValue[PlotRange]];
frameticks = AbsoluteOptions[p1, FrameTicks][[1, 2]];
ticks = {{}, {}};,
p1 = ListLinePlot[data, Axes -> True, Frame -> False,
GridLines -> OptionValue[GridLines],
PlotRange -> OptionValue[PlotRange], Ticks -> OptionValue[Ticks],
TicksStyle -> OptionValue[TicksStyle]];
ticks = AbsoluteOptions[p1, Ticks][[1, 2]];
frameticks = {{}, {}, {}, {}};
];

grids = AbsoluteOptions[p1, GridLines][[1, 2]];
opts1 = FilterRules[{opts}, Options[ListLinePlot]];
reverseOpts =
FilterRules[Options[ReverseListPlot], Options[ListLinePlot]];

Switch[OptionValue[ReverseAxis],
"X",
(* using map in case of multiple lists of data *)

data1 = (# /. {x_, y_} -> {-x, y} &) /@ data;
newXGrids = grids[[1]] /. {x_?NumericQ, z__} -> {-x, z};
newYGrids = grids[[2]];
newXTicks = ticks[[1]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
newYTicks = ticks[[2]];
{newXBottomTicks, newXTopTicks} =
frameticks[[{1, 3}]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
{newYLeftTicks, newYRightTicks} = frameticks[[{2, 4}]];,
"Y",
data1 = (# /. {x_, y_} -> {x, -y} &) /@ data;
newXGrids = grids[[1]];
newYGrids = grids[[2]] /. {x_?NumericQ, z__} -> {-x, z};
newXTicks = ticks[[1]];
newYTicks = ticks[[2]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
{newXBottomTicks, newXTopTicks} = frameticks[[{1, 3}]];
{newYLeftTicks, newYRightTicks} =
frameticks[[{2, 4}]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};,
"XY",
data1 = (# /. {x_, y_} -> {-x, -y} &) /@ data;
newXGrids = grids[[1]] /. {x_?NumericQ, z__} -> {-x, z};
newYGrids = grids[[2]] /. {x_?NumericQ, z__} -> {-x, z};
newXTicks = ticks[[1]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
newYTicks = ticks[[2]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
{newXBottomTicks, newXTopTicks} =
frameticks[[{1, 3}]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
{newYLeftTicks, newYRightTicks} =
frameticks[[{2, 4}]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
];

ListLinePlot[data1,
FrameTicks ->
Join[{newXBottomTicks, newYLeftTicks, newXTopTicks,
newYRightTicks}],
Ticks -> Join[{newXTicks, newYTicks}],
GridLines -> Join[{newXGrids, newYGrids}],
opts1,
reverseOpts
]
]

From: Armand Tamzarian on
On Sep 26, 5:13 am, Armand Tamzarian <mike.honeychu...(a)gmail.com>
wrote:
> On Sep 25, 4:58 am, Mather <sdzbb...(a)hotmail.com> wrote:
>
> > Hi,guys
> > I want to plot with a reversed Y-axis, that is to say, along the Y-
> > axis direction the numbers become smaller.
> > For example:
>
> > ListLinePlot[Table[{i, i^2}, {i, {1, 2, 3, 4, 5, 6}}],
> > PlotRange -> {{0, 8}, {50, 0}}]
>
> > However it does not work.
> > Can anybody help with this?
>
> > Thanks in advance!
>
> Clear[ReverseListPlot];
>
> ReverseListPlot::usage =
> "ReverseListPlot[{list1, list2, \[Ellipsis]}, options] will \
> generate a ListLinePlot with the \!\(\*FormBox[\"x\",
> TraditionalForm]\), \!\(\*FormBox[\"y\",
> TraditionalForm]\), or both \!\(\*FormBox[\"x\",
> TraditionalForm]\) and \!\(\*FormBox[\"y\",
> TraditionalForm]\), axes reversed. ReverseAxis \[Rule] \"X\", \
> ReverseAxis \[Rule] \"Y\", ReverseAxis \[Rule] \"XY\" are specific \
> options. Other options are the same as for ListLinePlot.";
>
> SyntaxInformation[
> ReverseListPlot] = {"ArgumentsPattern" -> {_, OptionsPattern[]}}=
;
>
> Options[ReverseListPlot] =
> Join[Options[ListLinePlot], {ReverseAxis -> "X"}];
>
> ReverseListPlot[data__List, opts : OptionsPattern[]] :=
> Module[{p1, frameticks, grids, ticks, opts1, reverseOpts, data1,
> newXGrids, newYGrids, newXTicks, newXBottomTicks, newXTopTicks,
> newYTicks, newYLeftTicks, newYRightTicks},
>
> (* make framed plot otherwise make axes plot.
> If Axes and Frame are both True no Ticks are produced in \
> ListLinePlot--only FrameTicks are produced,
> so need to produce these separately *)
>
> If[OptionValue[Frame] == True,
> p1 = ListLinePlot[data, Axes -> False, Frame -> True,
> GridLines -> OptionValue[GridLines],
> FrameTicks -> OptionValue[FrameTicks],
> FrameTicksStyle -> OptionValue[FrameTicksStyle],
> PlotRange -> OptionValue[PlotRange]];
> frameticks = AbsoluteOptions[p1, FrameTicks][[1, 2]];
> ticks = {{}, {}};,
> p1 = ListLinePlot[data, Axes -> True, Frame -> False,
> GridLines -> OptionValue[GridLines],
> PlotRange -> OptionValue[PlotRange], Ticks -> OptionValue[Tick=
s],
> TicksStyle -> OptionValue[TicksStyle]];
> ticks = AbsoluteOptions[p1, Ticks][[1, 2]];
> frameticks = {{}, {}, {}, {}};
> ];
>
> grids = AbsoluteOptions[p1, GridLines][[1, 2]];
> opts1 = FilterRules[{opts}, Options[ListLinePlot]];
> reverseOpts =
> FilterRules[Options[ReverseListPlot], Options[ListLinePlot]];
>
> Switch[OptionValue[ReverseAxis],
> "X",
> (* using map in case of multiple lists of data *)
>
> data1 = (# /. {x_, y_} -> {-x, y} &) /@ data;
> newXGrids = grids[[1]] /. {x_?NumericQ, z__} -> {-x, z};
> newYGrids = grids[[2]];
> newXTicks = ticks[[1]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
> newYTicks = ticks[[2]];
> {newXBottomTicks, newXTopTicks} =
> frameticks[[{1, 3}]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
> {newYLeftTicks, newYRightTicks} = frameticks[[{2, 4}]];,
> "Y",
> data1 = (# /. {x_, y_} -> {x, -y} &) /@ data;
> newXGrids = grids[[1]];
> newYGrids = grids[[2]] /. {x_?NumericQ, z__} -> {-x, z};
> newXTicks = ticks[[1]];
> newYTicks = ticks[[2]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
> {newXBottomTicks, newXTopTicks} = frameticks[[{1, 3}]];
> {newYLeftTicks, newYRightTicks} =
> frameticks[[{2, 4}]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};,
> "XY",
> data1 = (# /. {x_, y_} -> {-x, -y} &) /@ data;
> newXGrids = grids[[1]] /. {x_?NumericQ, z__} -> {-x, z};
> newYGrids = grids[[2]] /. {x_?NumericQ, z__} -> {-x, z};
> newXTicks = ticks[[1]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
> newYTicks = ticks[[2]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
> {newXBottomTicks, newXTopTicks} =
> frameticks[[{1, 3}]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
> {newYLeftTicks, newYRightTicks} =
> frameticks[[{2, 4}]] /. {x_?NumericQ, y_, z__} -> {-x, y, z};
> ];
>
> ListLinePlot[data1,
> FrameTicks ->
> Join[{newXBottomTicks, newYLeftTicks, newXTopTicks,
> newYRightTicks}],
> Ticks -> Join[{newXTicks, newYTicks}],
> GridLines -> Join[{newXGrids, newYGrids}],
> opts1,
> reverseOpts
> ]
> ]



Should have added some usage examples (incidentally you may notice
this function is relatively slow. Maybe others have ideas to improve
efficiency??):

data = Join[Table[{x, 7 x}, {x, -10, 0}], Table[{x, 0.5 x^3 + x^2 - 2
x}, {x, 0, 10}]];

data1 = Join[Table[{x, -3 x}, {x, -10, 0}], Table[{x, -3 x^3 + 15 x^2
+ 2 x}, {x, 0, 10}]];

ListLinePlot[{data, data1}, GridLines -> None, Axes -> True, Frame ->
True]

ReverseListPlot[{data1, data}, ReverseAxis -> "X", Frame -> True]

ReverseListPlot[{data, data1}, ReverseAxis -> "Y", GridLines -> None,
Frame -> True]

ReverseListPlot[{data1, data}, ReverseAxis -> "XY", Frame -> True]

ReverseListPlot[{data, data1}, ReverseAxis -> "X", GridLines ->
Automatic, Frame -> True]

ReverseListPlot[{data, data1}, ReverseAxis -> "XY", GridLines -> None,
Axes -> True, Frame -> False]

--Mike