Axes and Scales

Min-Hsuan Peng	  
Wolfram

(RowDefault[, (Spacer1), , (Spacer1), ])  #WolframTechConf

About this talk

ScalingFunctions

AxisObject and Its Usage in Viz

Grid[{{FlipView[Table[Plot[{Sinc[x],1/x,-1/x},{x,-limit,limit},ImageSize->700],{limit,{10,50,100,500}}]],
Plot[{Sinc[x],1/x,-1/x},{x,-Infinity,Infinity},ImageSize->700]}}]

ScalingFunctions and Axes

What is ScalingFunctions?

Plot[x^2,{x,0,10}]

Applying Log:

Plot[Log[x^2],{x,0,10}]

Juggling ticks around:

Plot[Log[x^2],{x,0,10},
Ticks->
{
Automatic,(*x-direction*)
{{-2,Exp[-2.]},{0,Exp[0]},{2,Exp[2.]},{4,Exp[4.]}}(*y-direction*)
}
]

Plot[Log[x^2],{x,0,10},
Ticks->
{
Automatic,
{{Log[0.1],0.1},{Log[10],10},{Log[100],100}}
}
]

Plot[x^2,{x,0,10},
ScalingFunctions->"Log"
]

Domain scaling

Plot[(x)^2,{x,0.1,10}]

Variable replacement:

x:=Exp[xx]

Plot[(Exp[xx])^2,{xx,Log[0.1],Log[10]},
Ticks->
{
{{Log[0.1],0.1},{Log[0.5],0.5},{Log[5],5},{Log[10],10}},
Automatic
}
]

Plot[x^2,{x,0.1,10},
ScalingFunctions->{"Log",None}
]

ScalingFunctions Syntax

Named scales: “Log”, “Log10”,”Reverse”,”Reciprocal”,”SignedLog”,”Infinite”

General case: {scale, inverse scale}, like {Log, Exp}, {Log2[#]&, 2^#&}

ScalingFunctions -> {x-direction, y-direction, z-direction}

Log

Ticks differences for Log, Log2, Log10

Plot[x,{x,1,100},
ScalingFunctions->"Log2"
]

Plot[x,{x,1,75},
ScalingFunctions->"Log10"
]

Plot[x,{x,1,75},
ScalingFunctions->"Log"
]

Specify ScalingFunctions for each direction:

Plot[x^2,{x,1,100},
ScalingFunctions->{"Log","Log"}
]

Reverse

Plot[x^2,{x,-5,5},
ScalingFunctions->"Reverse"(*{-# &, -# &}*)
]

Reciprocal

Plot[x^2,{x,-5,5},
ScalingFunctions->"Reciprocal"(*{1/# &, 1/# &}*)
]

SignedLog

Log of negative values are dropped:

Plot[Sin[x],{x, -10,10},
ScalingFunctions->"Log"
]

SignedLog: shifted log

Plot[Sign[x]E^(Abs@x), {x, -3,3}]

Plot[Sign[x]E^(Abs@x), {x, -3,3},ScalingFunctions->"Log"]

f[x_]:=Sign[x] (Log[Abs[x] +1])

Plot[Sign[x]Exp[Abs@x],{x, -3,3},
ScalingFunctions->{None,"SignedLog"}
]

Log of Sin[x] again:

Plot[Sin[x],{x, -10,10},
ScalingFunctions->{"SignedLog",0.1}
]

InfiniteScale - domain scaling

Plot[Sinc[x],{x,-Infinity,Infinity}]

f[x_]:=Rescale[x,{-Infinity,Infinity},{-1,1}]

InverseFunction[f][x]

f[x]

Plot[f[x],{x,-100,100}]

Similar functions: Tanh, Erf, LogisticSigmoid...

Plot[{Tanh[x],Erf[x],2LogisticSigmoid[x]-1},{x,-5,5},PlotLegends->"Expressions"]

Using {“Infinite”, Interval[..]} to specify region of interest

Plot[Sin[x]/x,{x,-Infinity,Infinity},
ScalingFunctions->{"Infinite",None}]

Finding the limit:

Limit[(((1-(1/x)))^x),x->Infinity]

Plot[(((1-(1/x)))^x),{x,1,Infinity},
Epilog->{Red,InfiniteLine[{{0,1/E},{1,1/E}}]},
PlotRange->{All,{0,1/2}}
]

Limit[((3 (x^5)+2 (x^3)+1 x+2)/(2 (x^5)+10 (x^4)+2 (x^2)+1)),x->Infinity]

Plot[((3 (x^5)+2 (x^3)+1 x+2)/(2 (x^5)+10 (x^4)+2 (x^2)+1)),{x,-Infinity,Infinity},
Epilog->{Red,InfiniteLine[{{0,3/2},{1,3/2}}]}
]

Bonus: use ScalingFunctions as a function reference

Plot[{x^2-1,x^2-x,Style[x^2,Red]},{x,0,5},
ScalingFunctions->{None,{Sqrt[#]&,#^2&}},
PlotLabels->"Expressions",
ImageSize->800]

DateScale

ListPlot uses date axis to show TimeSeries data automatically:

ListLinePlot[FinancialData["AAPL",{(DateObject["Fri 1 Jan 2021", DateObject[{2021,1,1},"Day"]]),(DateObject["Fri 31 Dec 2021", DateObject[{2021,12,31},"Day"]])}]]

sunsetdata={
Table[
{date,TimeObject[Sunrise[Here,date]]},
{date,DateRange[(DateObject["Fri 1 Jan 2021", DateObject[{2021,1,1},"Day"]]),(DateObject["Fri 31 Dec 2021", DateObject[{2021,12,31},"Day"]])]}
],
Table[
{date,TimeObject[Sunset[Here,date]]},
{date,DateRange[(DateObject["Fri 1 Jan 2021", DateObject[{2021,1,1},"Day"]]),(DateObject["Fri 31 Dec 2021", DateObject[{2021,12,31},"Day"]])]}
]
};

ListLinePlot[
,
ScalingFunctions->{"Date","Date"},
PlotLegends->{"Sunrise","Sunset"}
]

More applications to come

ListLinePlot3D[FinancialData[#,{(DateObject["Fri 1 Jan 2021", DateObject[{2021,1,1},"Day"]]),(DateObject["Fri 31 Dec 2021", DateObject[{2021,12,31},"Day"]])}]&/@{"GOOG","AMZN"},
PlotRange->{All,{0,3},All},
Filling->Bottom,
PlotLegends->{"GOOG","AMZN"}]

Functions with ScalingFunctions

EntityClass["WolframLanguageSymbol","OptionNames"->ContainsAll[{"ScalingFunctions"}]]//EntityList

AxisObject

See James Lane’s talk on “Graphics: New Features and Improvements” at 11:30 on Thursday.

Ticks

Ticks specification

({{      , (RefLink[None, paclet:ref/None]), no tick marks drawn }, {      , (RefLink[Automatic, paclet:ref/Automatic]), tick mark positions and labels chosen automatically }, {      , {(Subscript[x, 1]),(Subscript[x, 2]),…}, tick marks drawn at the specified positions }, {      , {{(Subscript[x, 1]),(Subscript[label, 1])},{(Subscript[x, 2]),(Subscript[label, 2])},…}, tick marks drawn with the specified labels }, {      , {{(Subscript[x, 1]),(Subscript[label, 1]),(Subscript[len, 1])},…}, tick marks with specified scaled length }, {      , {{(Subscript[x, 1]),(Subscript[label, 1]),{(Subscript[plen, 1]),(Subscript[mlen, 1])}},…}, tick marks with specified lengths in the positive and negative directions }, {      , {{(Subscript[x, 1]),(Subscript[label, 1]),(Subscript[len, 1]),(Subscript[style, 1])},…}, tick marks with specified styles }, {      , func, a function to be applied to (Subscript[x, min]), (Subscript[x, max]) to get the tick mark specification }})

Plot[x^2,{x,0,10},ScalingFunctions->"Log"]

Plot[x^2,{x,0,10},
Ticks->
{
Automatic,
{{1,1},{10,10},{100,100}}
},
ScalingFunctions->"Log"
]

AxisObject

Graphics[
{
AxisObject[Line[{{0,0},{1,1}}],{0,100},
TickLengths->{0.1,0.05},
(*TicksStyle->{Directive[Thick,Red],Blue},*)
(*TickPositions->{{Range[0,100,20]},{Range[10,100,20]}},*)
(*TickLabels->{{"a","b","c","d","e"}},*)
LabelStyle->20
]
},Frame->True]

ternaryFrame=Graphics[{
AxisObject[Line[{{1,0},{0,0}}],{0,100},
AxisLabel->Placed["Component A",{0.5,{0.5,2.5}}],RotateLabel->Automatic,
TickDirection->"Inward",
LabelStyle->20,
TickLengths->0.01
],
AxisObject[Line[{{0,0},{0.5,(Sqrt[3])/2.}}],{0,100},
AxisLabel->Placed["Component B",{0.5,{0.5,-2.0}}],RotateLabel->60Degree,
TickDirection->"Inward",
LabelStyle->20,
TickLengths->0.01
],
AxisObject[Line[{{0.5,(Sqrt[3])/2.},{1,0}}],{0,100},
AxisLabel->Placed["Component C",{0.5,{0.5,-2.0}}],
RotateLabel->-60Degree,
TickDirection->"Inward",
LabelStyle->20,
TickLengths->0.01
]},
PlotRange->{{0,1},{0,1}}
]

Visualization functions that will switch to use AxisObject

RadialAxisPlot

RadialAxisPlot[RandomReal[1,{5,6}],Ticks->All]

ParallelAxisPlot

n=100;data=RandomReal[{0,20},n];
ParallelAxisPlot[
Transpose[{data,Sort[data],-Sort[data],2 Sort[data],2 Sort[data]+15,Exp[Sort[data]],(1/(Sort[data]))}]
]

BarChart, TradingChart, PairedBarChart, PariedHistogram, etc...

BarChart[Range[10],ChartLabels->Alphabet[],LabelStyle->20]

TradingChart["AAPL",PerformanceGoal->"Speed"]

PairedBarChart[RandomReal[1,{2,5}],RandomReal[1,{2,5}]]

AxisObject with ScalingFunctions

Graphics[AxisObject[{"Horizontal",0,{1,10}},ScalingFunctions->"Log"],
Frame->True,
FrameStyle->Blue,
LabelStyle->20]

Graphics[{
AxisObject[{"Horizontal",1,{1,10}},ScalingFunctions->"Log"],
AxisObject[{"Horizontal",0,{1,10}},{1->0.01,10->10},ScalingFunctions->"Log"]
},LabelStyle->20]

Graphics[{
AxisObject[{"Horizontal",0,{-1,1}},ScalingFunctions->"Infinite"]
},LabelStyle->20]

Questions?

Join our office hour today at 2pm

$PlotTheme={"Presentation","ThickLines","LargeLabels"}