Wolfram Research

Function Repository Resource:

MultipleAxesPlot

Source Notebook

Display different vertical axes for two plotted expressions

Contributed by: Jon McLoone

ResourceFunction["MultipleAxesPlot"][{expr1,expr2},{x,xmin,xmax}]

generates a plot of expr1 and expr2 with two y axes.

Details and Options

ResourceFunction["MultipleAxesPlot"] supports all of the options of Plot except Axes, ScalingFunctions, Frame, Ticks, TicksStyle and FrameTicks.

Examples

Basic Examples

Plot two functions with different scales:

In[1]:=
ResourceFunction["MultipleAxesPlot"][{Sin[x], 4 Cos[x]}, {x, 0, 6}]
Out[1]=

Options

To make it clearer which axes refers to which line you can use "SecondaryAxesColor":

In[2]:=
ResourceFunction["MultipleAxesPlot"][{Sin[x], Exp[x]}, {x, 0, 6}, PlotStyle -> {Black, Blue}, "SecondaryAxesColor" -> Blue]
Out[2]=

You can control the plot ranges of the two lines using PlotRange and "SecondaryPlotRange":

In[3]:=
ResourceFunction["MultipleAxesPlot"][{Sin[x], Exp[x]}, {x, 0, 6}, PlotRange -> {0, 1.1}, "SecondaryPlotRange" -> {100, 400}]
Out[3]=

PlotRangePadding applies to both functions but uses the coordinate system of the first function:

In[4]:=
ResourceFunction["MultipleAxesPlot"][{Sin[x], Exp[x]}, {x, 0, 6}, PlotStyle -> {Black, Blue}, PlotRangePadding -> {Automatic, 2}]
Out[4]=

MultipleAxesPlot supports all of the options of Plot except Axes, ScalingFunctions, Frame, Ticks, TicksStyle and FrameTicks.

Resource History

License Information