Hi Christian, At Sun, 19 Aug 2012 20:50:20 +0200, Christian Feuersaenger wrote: > what you seem to want is something related to the 'symbolic x coords' > feature. That feature would expect input *coordinates* of the form > (aaa,20) and would automatically map them to numbers - and backwards. > The advantage is: pgfplots takes care of assigning suitable tick > positions (based on the numeric coordinates, their range, and the size > of the image).
Yes, it seems so. > In your case, you have numeric input and want textual labels - and it > seems as if you have some kind of integer-based tick label scheme. Unfortunately, not really. I have plots with >1000 data points. I'd like to provide labels for, say, 50 and let pgfplots choose the most appropriate ones. > Perhaps you can create a 'x coord inv trafo' *without* a 'x coord trafo' > -- and use the same code as for symbolic coordinates? This would allow > you to What do you mean by "use the same code as for symbolic coordinates"? Which code exactly? It turns out the only labels that I need to transform are seconds to more readable units so I just wrote a macro to translate seconds to a more reasonable representation. Using your x coord inv trafo works in a simple case, but when I try to include it in a macro, TeX complains. First, here is a complete example of the simple case: \documentclass{article} \usepackage{tikz} \usepgflibrary{fpu} \usepackage{pgfplots} \usepackage{filecontents} \begin{document} % number % threshold % divisor % suffix % else \def\secondspphelper#1#2#3#4#5{% \pgfmathfloatparsenumber{#1}% \edef\num{\pgfmathresult}% \pgfmathfloatparsenumber{#2}% \edef\threshold{\pgfmathresult}% \pgfmathfloatparsenumber{#3}% \edef\divisor{\pgfmathresult}% % \pgfmathfloatlessthan{\num}{\threshold}% \ifdim\pgfmathresult pt = 1 pt% \pgfmathfloatdivide{\num}{\divisor}% \pgfmathfloattofixed{\pgfmathresult}% \pgfmathprintnumberto[/pgf/number format/precision=1]{\pgfmathresult}{\pgfmathresult}% \edef\pgfmathresult{\pgfmathresult~#4}% \else% #5% \fi% }% % Pretty print a number of seconds. % Example: % \secondspp{1000}\pgfmathresult == 16.7~m \def\secondspp#1{% % Print as seconds for values up to 90 seconds. \secondspphelper{#1}{90}{1}{s}{% % Print as minutes for values up to 1 hour (= 3600 seconds) \secondspphelper{#1}{3600}{60}{m}{% % Print as hours for values up to 1 day (= 86400 seconds) \secondspphelper{#1}{86400}{3600}{h}{% % Print as days for up to 2 weeks (= 1209600 seconds) \secondspphelper{#1}{1209600}{86400}{d}{% % Print as weeks. \secondspphelper{#1}{Inf}{604800}{w}{}% }% }% }% }% } \begin{tikzpicture} \begin{axis}[ xticklabel={\tick}, scaled x ticks=false, plot coordinates/math parser=false, x coord inv trafo/.code={\secondspp{#1}}] \addplot[domain=1:1000] {x}; \end{axis} \end{tikzpicture} \end{document} Now, the full story and my new problem. Unfortunately, my plots are being generated by a program. I include them using \input (behind a macro called \includepgfplot). Further, each plot is actually a set of plots: one plot for each of my data sets. As such, I wrote another macro that does the layout and expands a plot template macro. When I try to include the x coord inv trafo as an argument, TeX complains (see below). I've been working on this most of the day without success, but my TeX-foo is just not good enough... I would greatly appreciate any help. I'm sorry I didn't manage to make my example shorter. % Include a plot. You need to enclosure it in a tikzpicture % environment. % % Takes two arguments: additional axis arguments and the name of the % file. Example: % % \begin{includepgfplot}[width=.35\textwidth]{plot} % % Any additional tikz drawing commands. % \end{includepgfplot} \newenvironment{includepgfplot}[2][]{% \def\AdditionalAxisArgs{#1}% \input{#2}% }{% \EndAxis% } % A generated plot. Define the \AdditionalAxisArgs macro to % additional axis arguments. \begin{filecontents}{plot.tex} \def\BeginAxis{\begin{axis}[}% \expandafter\BeginAxis\AdditionalAxisArgs]% \addplot[domain=1:1000] {x};% \def\EndAxis{\end{axis}}% \end{filecontents} % Set up a plot. #1 should be an axis environment. It should set the % axis options to include \useraxisoptions. \def\layoutplot#1{% \begin{tikzpicture}% \edef\useraxisoptions{small}% #1% \end{tikzpicture}% } % This works: % % \layoutplot{ % \begin{includepgfplot}[\useraxisoptions]{plot} % \end{includepgfplot} % } % This results in: % ! Illegal unit of measure (pt inserted). % <to be read again> % x % l.112 ...oord inv trafo/.code={\secondspp{####1}}} % { \layoutplot{width=.35\textwidth, xticklabel={\noexpand\tick}, scaled x ticks=false, plot coordinates/math parser=false, x coord inv trafo/.code={\secondspp{####1}}}{ \begin{includepgfplot}[\useraxisoptions]{plot} \end{includepgfplot} } Thanks, Neal ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Pgfplots-features mailing list Pgfplots-features@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pgfplots-features