Reverse axis plot

Version 0.1

Initialization

BeginPackage["ReverseListPlot`"]

(* Exported symbols added here with SymbolName::usage *) 

ReverseListPlot::usage="ReverseListPlot[{list1, list2, …}, options] will generate a ListLinePlot with the x, y, or both x and y, axes reversed. ReverseAxis -> \"X\", ReverseAxis -> \"Y\", ReverseAxis -> \"XY\" are specific options. Other options are the same as for ListLinePlot.";

ReverseAxis;

Unprotect[ReverseListPlot];

Begin["`Private`"]
(* Implementation of the package *)

Clear[ReverseListPlot];

SyntaxInformation[ReverseListPlot]={"ArgumentsPattern"->{_,OptionsPattern[]}};
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
]
]

End[];

Protect[ReverseListPlot];

EndPackage[]

Examples

data=Join[Table[{x,-x+8x},{x,-10,0}],Table[{x,0.5(x^3)+ (x^2)-2x},{x,0,10}]];
data1=Table[{x,(x^3)},{x,-10,10}];
data2=Table[{x,18.*(x^2)},{x,-10,10}];

p1=ListLinePlot[-data,Axes->True,Frame->True]
frameticks=AbsoluteOptions[p1,FrameTicks][[1,2]];
ticks=AbsoluteOptions[p1,Ticks][[1,2]];

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

Now reverse the axes on some plots:

(* reverse the ticks on x and y axis *)

ReverseListPlot[data,ReverseAxis->"XY",GridLines->None,Axes-> True,Frame->True]

(* reverse the ticks on x and y axis *)

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

(* reverse the ticks on x and y axis *)

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

(* reverse the ticks on y axis *)

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

Add grid lines.

(* reverse the ticks on an x axis *)

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

Operate on multiple sets of data.

(* reverse the ticks on an x axis *)

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

(* reverse the ticks on an x and y axes *)

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