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.

I have measured the execution time of two algorithms (a naive, and an optimized one), and I would like to display measured data with pgfplots plus a trend line for the naive algorithm.

I have used Matlab's cftool to get a polynomial function for trend line:

Linear model Poly2:
    fittedmodel(x) = p1*x^2 + p2*x + p3
    Coefficients (with 95% confidence bounds):
        p1 = 1.61e-06 (1.61e-06, 1.61e-06)
        p2 = -0.003371 (-0.003636, -0.003107)
        p3 = -0.0772 (-5.333, 5.179)

>> vpa(fittedmodel.p1)

ans =

0.0000016101333575269318185488581079978

>> vpa(fittedmodel.p2)

ans =

-0.0033714174188680659169370379402153

>> vpa(fittedmodel.p3)

ans =

-0.077204674695659905592215466185735

But plotting everything into one figure pgfplots produces an erroneous line for the trend line at low values.

I am using gnuplot for the trend line, because pgfplots did not even make any output for low values.

I do not know what I'm doing wrong, probably the precision is not big enough. If that is the problem, how can I improve it?

Here is my MWE:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, shapes, pgfplots.units, pgfplots.dateplot, calendar}
\pgfplotsset{width=12cm, compat=newest}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

\begin{tikzpicture}%[font=\large\sffamily]
    \begin{loglogaxis}[/pgf/number format/.cd,use comma,%
    use units=true,%
    y unit=s,%
    y unit prefix=m,%
    ylabel={Fut\'{a}si id\H{o}},%
    scaled y ticks=false,%
    y tick label style={/pgf/number format/fixed,%
        /pgf/number format/1000 sep=\thinspace},%
    x unit=n,%
    xlabel={Bemenet},%
    legend pos=north west,%
    legend style={draw=none}]
        \addplot+[mark=*,%
            mark options={scale=0.5,fill=blue,draw=blue},%
            color=blue] table[col sep=semicolon,%
            x=n,%
            y=t_naive] {exectime.csv};
        \addlegendentry{naive}

        \addplot[mark=none,%
            style=dashed,%
            color=blue!50!white,%
            domain=1:1000000000,%
            samples=1000] gnuplot {0.0000016101333575269318185488581079978 * x^2 - 0.0033714174188680659169370379402153 * x - 0.077204674695659905592215466185735};
        \addlegendentry{naive trend}

        \addplot+[mark=*,%
            mark options={scale=0.5,fill=red,draw=red},%
            color=red] table[col sep=semicolon,%
            x=n,%
            y=t_optimized] {exectime.csv};
        \addlegendentry{optimized}
    \end{loglogaxis}
\end{tikzpicture}

\end{document}

Here is the content of the exectime.csv file:

n;t_naive;t_optimized
1;0.00549499999999999;0.00004500000000000
2;0.00557399999999999;0.00004500000000000
3;0.00567399999999998;0.00017300000000000
4;0.00568299999999998;0.00017300000000000
5;0.00579299999999997;0.00021100000000000
6;0.00607500000000001;0.00047400000000000
7;0.00633200000000002;0.00059600000000000
8;0.00651200000000000;0.00077000000000000
9;0.00679999999999998;0.00088800000000000
10;0.00690799999999997;0.00093600000000000
20;0.00881400000000000;0.00188800000000000
30;0.01110500000000000;0.00308100000000000
40;0.01380300000000000;0.00416600000000000
50;0.01744700000000000;0.00563000000000000
60;0.02035800000000000;0.00680900000000001
70;0.02407600000000000;0.00820300000000001
80;0.02794400000000000;0.00928900000000000
90;0.03238200000000000;0.01039000000000000
100;0.03820100000000000;0.01162200000000000
200;0.09925500000000000;0.02850100000000000
300;0.19628100000000000;0.04459999999999990
400;0.29108000000000000;0.06029799999999990
500;0.42527000000000000;0.07618300000000010
600;0.58424000000000000;0.09287300000000000
700;0.79010700000000000;0.11013500000000000
800;0.98573400000000000;0.12708500000000000
900;1.21879600000000000;0.14422200000000000
1000;1.48462400000000000;0.16221400000000000
2000;5.56059100000000000;0.35208600000000000
3000;12.10970900000000000;0.54000899999999900
4000;21.03929400000000000;0.72470000000000000
5000;32.41173900000000000;0.91246400000000100
6000;46.36602000000000000;1.11181800000000000
7000;62.61670900000000000;1.30629200000000000
8000;81.58859900000000000;1.51091900000000000
9000;102.89399700000000000;1.71370300000000000
10000;126.75557200000000000;1.92297700000000000
25000;844.62786300000000000;5.06326700000000000
50000;3816.58308900000000000;10.59345300000000000
75000;8806.76242100000000000;16.10985800000000000
100000;15800.83862700000000000;22.00894600000000000
1000000;1606761.62740000000000000;232.43642700000000000
10000000;;2462.02062400000000000
100000000;;25872.93018000000000000
1000000000;;274393.61750000000000000
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You can inspect the output of gnuplot in <filename>.pgf-plot.table. Apparently, the first ~300 entries have "type=u" (seems to mean "unbounded"). Pgfplots ignores that flag (perhaps it should process it), that's why it produces wrong output.

If I generate the trend line with pgfplots, I get the same data points as gnuplot - except that pgfplots automatically skips all unbounded coordinates.

All these unbounded values are associated with negative function values of the trend line, and the log of negative values is undefined.

share|improve this answer
    
Thanks. (I feel a little stupid right now.) –  szantaii Nov 10 '12 at 15:44
    
@szantaii no problem. After all, one could have expected that (a) pgfplots is capable of reading gnuplot's output completely and omit the unbounded entries and (b) that pgfplots provides a readable warning (it provides one, but that is hard to read because it uses internal float representation). I'll try to fix that in pgfplots eventually. –  Christian Feuersänger Nov 10 '12 at 20:24
add comment

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.