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 [email protected]:
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/pgfplots-features
\documentclass[a4paper]{article}
\usepackage{german}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}
\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}
P.pdf
Description: Adobe PDF 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 [email protected] https://lists.sourceforge.net/lists/listinfo/pgfplots-features
