Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

If I have a data set in which most of the interesting stuff happens for small values of x then I can use \begin{semilogxaxis} ... \end{semilogxaxis} to create a plot with a logarithmic x axis, which has the effect of compressing the plot for large x values and using more of the plot area for small values of x.

I have a data set where 0 < x < 1 and everything interesting happens for values of x close to 1. I would therefore like to do the opposite of a log plot: use a custom function to specify the progression along the x axis so that large values of x occupy a disproportionately large part of the plot area.

I know I could hack this by transforming the x values in my data and then faking custom tick labels, but is there an easy way to get pgfplots to do this automatically?

share|improve this question
1  
Easy way? I don’t know. There are certain keys to transform input data (here x filter and x coord trafo). –  Qrrbrbirlbel May 17 '13 at 13:46

1 Answer 1

up vote 3 down vote accepted

In principle pgfplots provides what you need. Especially the x coord trafo section of the manual helps as Qrrbrbirlbel has mentioned.

Here is a very simple example:

\documentclass[tikz,12pt,preview]{standalone}

\usepackage{filecontents}

\begin{filecontents*}{transform.dat}
1   1
2   4
3   9
4   16
\end{filecontents*}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.8} 
\usetikzlibrary{plotmarks,calc} 

\begin{document}

\begin{tikzpicture}

\pgfplotsset{
x coord trafo/.code={\pgfmathparse{#1^2}\pgfmathresult},
x coord inv trafo/.code={\pgfmathparse{#1}\pgfmathresult},
}

\begin{axis}[ylabel={$f(x)=x^2$},xlabel=$x^2$]
    \addplot table {transform.dat};
\end{axis}
\end{tikzpicture} 

\end{document}

Here the x-axis is transformed and the final result is a straight line again:

enter image description here

share|improve this answer
    
You should use x coord inv trafo/.code={\pgfmathparse{sqrt(#1)}\pgfmathresult}, otherwise the tick values are wrong. Note that automatic "nice" tick selection doesn't work in this case, you'll have to set the tick values manually using something like xtick={0,...,4}. –  Jake May 17 '13 at 15:24
    
Thanks, this is just what I wanted. –  Ubiquitous May 20 '13 at 9:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.