Dear Ken,

I am sorry, it seems I have done two mistakes: first, I have used a PGF CVS macro (\pgfmathint). Second, it seems I have sent the wrong P.pdf file -- because the one I wanted to sent actually *had* the widthxheight strings as x coordinates. Strange, I must have been tired.

Nevertheless, if you add the lines

\makeatletter
\pgfutil@ifundefined{pgfmathint}{%
    \def\pgfmathint#1{\expandafter\pgfmathint@#1\relax}%
    \def\pgfmathint@#1.#2\relax{\def\pgfmathresult{#1}}%
}{%
}%
\makeatother

to your preamble, you will get a "light" version of that missing macro which will do the job. Once the PGF CVS version becomes the current stable, the stable \pgfmathint will be used instead.

I have attached an updated P.tex and P.pdf (hopefully the correct ones this time).

Best regards

Christian

Am 08.03.2011 01:27, schrieb garbage...@arcor.de:
Hello Christian,

first of all, thank you for your fast response.
Sounds like my guess was right, using the 'x coord trafo' is the right way to 
accomplish my needs.

Unfortunately your attached draft dosn't compile on my machine.
The compiler is telling me ./P.tex:67: Undefined control sequence.
I'm using the MacTeX-2010 distribution bases on TeX Live 2010.
I attached the error log.

Now in the pdf you attached, the x-axis coords are integers but I like to get 
the 'widthxheight' strings in my plot instead.
I thought that is the purpose of 'x coord inv trafo' that has to be defined... 
or am I messing things up here?
Maybe you could shed some light on it.

Best regards

Ken

Am 07.03.2011 um 22:21 schrieb Christian Feuersaenger:

Hello Ken,

thank you for your feedback!

Yes, it is indeed possible to use the 'x coord trafo' key to create such a 
dictionary dynamically.

Does the attached draft fulfill your needs?

It re-generates a dictionary for every new encountered coordinate (!).  It also 
contains an (uncommented) hint how to re-use existing dictionary entries 
without overwriting them, in case you need it (try it out).
If you need it, you may also want to reset the assigned numbers before 
processing a further plot: this can be realized by placing
\global\kencount=0
just before an \addplot or \begin{axis} statement (again, try it out).

Note that the coordinates are mapped in the order of appearance -- you will 
need to sort the data.


Best regards

Christian

Am 07.03.2011 13:35, schrieb garbage...@arcor.de:
Hello everyone,

pgfplots supports the "symbolic x coords" key which implements a dictionary 
which maps strings to numerical
data and backwards automatically.

I am trying to plot a datafile with x values representing different image resolutions. 
These values are strings in the format "widthxheight". Currently i'm using

\begin{axis}[symbolic x coords={64x64, 122x34, 64x128,...,128x128, 128x136, 
128x256}, xtick=data]

to provide a string dictionary to pgfplots.

For some reason the datafile could contain a huge number of different (random) 
resolution strings and i don't like the idea to adjust the fixed dictionary to 
get my plot right, every time the datafile has changed.

Is there a way to use pgfplots with some kind of a dynamic dictionary maybe 
generated from the x coords in the datafile?

Another way could be the use of 'the x coord trafo' key i read about in the 
manual. The Resolutions strings need to be transformed to numbers. But i have 
no idea how to use x coord trafo in my case and how i transform an random 
string into a running numerical index. I admit, i have very little knowledge 
about tikz, pgf and latex macros.
Any ideas how to do this?

Here's an example of the datafile format I'm talking about:

#resolution min_µs avg_µs max_µs
64x64 431 1060 6225
64x128 468 589 1424
128x128 488 558 1112
128x136 520 655 1612
...
128x256 670 750 1783

Best regards

Ken

------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________
Pgfplots-features mailing list
Pgfplots-features@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pgfplots-features


------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d


_______________________________________________
Pgfplots-features mailing list
Pgfplots-features@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pgfplots-features

Attachment: P.pdf
Description: Adobe PDF document

\documentclass[a4paper]{article}
\usepackage{german}
\usepackage[utf8]{inputenc}

\usepackage{pgfplots}

\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}

\makeatletter
\pgfutil@ifundefined{pgfmathint}{%
	\def\pgfmathint#1{\expandafter\pgfmathint@#1\relax}%
	\def\pgfmathint@#1.#2\relax{\def\pgfmathresult{#1}}%
}{%
}%
\makeatother

\newcount\kencounter
\global\kencounter=0

\pgfplotsset{
    dynamic dict/.style={
        x coord trafo/.code={%
            %\pgfkeysifdefined{/ken/key ##1}{%
                % re-use existing key.
            %   \pgfkeysgetvalue{/ken/key ##1}\pgfmathresult%
            %}{%
                % dynamically define a new key with integer value of
                % \kencounter:
                \edef\pgfmathresult{\the\kencounter}%
                % this is the new key:
                \global\pgfkeyslet{/ken/key ##1}\pgfmathresult
                % remember inverse for the inverse trafo:
                \global\pgfkeyslet{/ken/key no \pgfmathresult}{##1}%
                \global\advance\kencounter by 1
                % NOTE: \global makes the following definition in GLOBAL
                % namespace. 
            %}%
        },
        x coord inv trafo/.code={%
            % truncate 0.0 -> 0;  1.5 --> 1
            \pgfmathint{##1}%
            % lookup inverse!
            \pgfkeysifdefined{/ken/key no \pgfmathresult}{%
                \pgfkeysgetvalue{/ken/key no \pgfmathresult}\pgfmathresult%
            }{%
                \PackageError{pgfplots}{Inverse trafo for \pgfmathresult\space failed: no such key!}{}%
            }%
        },
        xticklabel={\tick},
        scaled x ticks=false,
        plot coordinates/math parser=false,
        xticklabel style={rotate=45,anchor=east},
        xtick=data,
    },
}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        dynamic dict,
    ]

    \addplot table {
x y W H
64x64 431 1060 6225
64x128 468 589 1424
128x128 488 558 1112
128x136 520 655 1612
128x256 670 750 1783
    };
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{axis}[
        dynamic dict,
    ]

    \addplot table {
x y W H
64x64 431 1060 6225
128x64 468 589 1424
128x128 488 558 1112
128x136 520 655 1612
128x256 670 750 1783
256x256 670 750 1783
512x512 670 750 1783
    };
    \end{axis}
\end{tikzpicture}
\end{document}

------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________
Pgfplots-features mailing list
Pgfplots-features@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pgfplots-features

Reply via email to