1.8.9 Linked axes

Often it may be desired that multiple axes on a graph share a common range, or be related to one another by some algebraic expression. For example, a plot with wavelength $$λ$ of light as one axis may usefully also have parallel axes showing frequency of light $ν=c/λ$ or photon energy $E=hc/λ$. The following example sets the {\tt x2} axis to share a common range with the {\tt x} axis: 

\begin{verbatim} 
set axis x2 linked x
\end{verbatim}

 An algebraic relationship between two axes may be set by stating the algebraic relationship after the keyword {\tt using}, as in the following example which implement the formulae shown above for the frequency and energy of photons of light as a function of their wavelength: 

\begin{verbatim} 
set xrange [200*unit(nm):unit(800*nm)]
set axis x2 linked x1 using phy.c/x
set axis x3 linked x2 using phy.h*x
\end{verbatim}

 As in the {\tt set xformat} command, a dummy variable of {\tt x}, {\tt y} or {\tt z} is used in the linkage expression depending on the direction of the axis being linked to, but a dummy variable of {\tt x} is still used when linking to, for example, the {\tt x2} axis. 

As these examples demonstrate, the functions used to link axes need not be linear. In fact, axes with any arbitrary mapping between position and value can be produced by linked in a non-linear fashion to another linear axis, which, if desired, can then be hidden using the {\tt set axis invisible} command. Multi-valued mappings are also permitted. Any data plotted against the following {\tt x2}-axis for a suitable range of {\tt x}-axis 

\begin{verbatim} 
set axis x2 linked x1 using x**2
\end{verbatim}

 would appear twice, symmetrically on either side of 

$x=0$. 

Insofar as is possible, linked axes autoscale intelligently when no range is set. Thus, if the {\tt x2}-axis is linked to the {\tt x}-axis, and no range to set for the {\tt x}-axis, the {\tt x}-axis will autoscale to include all of the data plotted against both itself and the {\tt x2}-axis. Similarly, if the {\tt x2}-axis is linked to the {\tt x}-axis by means of some algebraic expression, the {\tt x}-axis will attempt to autoscale to include the data plotted against the {\tt x2}-axis, though in some cases – especially with non-monotonic linking functions – this may prove too difficult. Where Pyxplot detects that it has failed, a warning is issued recommending that a hard range be set for – in this example – the {\tt x}-axis. 

 \upshape \mdseries \rm \vspace{-5mm} \begin{longtable}{|>{\columncolor {LightGrey}}p{\textwidth }|} In this example we produce a plot of blackbody spectra for five different temperatures 

\end{longtable}

$T$, using the Planck formula \[  B_\nu (\nu ,T)=\left(\frac{2h^3}{c^2}\right)\frac{\nu ^3}{\exp (h\nu /kT)-1}  \] which is evaluated in Pyxplot by the system-defined mathematical function {\tt Bv(nu,T)}. We use the axis linkage commands listed as an example in the text of Section~ \ref{sec:linked_ axes} to produce three parallel horizontal axes showing wavelength of light, frequency of light and photon energy. \vspace{3mm}\\ \noindent \input{examples/tex/ex_ multiaxes_1.tex} \vspace{3mm}\\ \noindent \centerline{\includegraphics[width=10cm]{examples/eps/ex_ multiaxes}}  $

In this example we produce a plot of the temperature of the cosmic microwave background radiation (CMBR) as a function of time

$$t$ since the Big Bang, on the {\tt x}-axis, and equivalently as a function of redshift $z$, on the {\tt x2}-axis. The specialist cosmology function {\tt ast\_ \- Lcdm\_ \- z(}$t$,\- $H_0$,\- $Ω_M$,\- $Ω_$)$ is used to make the highly non-linear conversion between time $$t$ and redshift $z$, adopting some standard values for the cosmological parameters $H_0$, $Ω_M$ and $Ω_$. Because the temperature of the CMBR is most easily expressed as a function of redshift as $T=2.73 K/(1+z)$, we plot this function against axis {\tt x2}. \vspace{3mm}\\ \noindent \input{examples/tex/ex_ cmbrtemp_1.tex} \vspace{3mm}\\ \noindent \centerline{\includegraphics[width=8cm]{examples/eps/ex_ cmbrtemp}}  $