TransWikia.com

How can I get pgfplotstabletypeset options to work inside of code for another pgf key?

TeX - LaTeX Asked on December 5, 2020

Consider the code:

documentclass{article}
usepackage{tikz}
usepackage{pgfplots}
usepackage{gnuplottex}
usepackage{pgfkeys}
usepackage{pgfplotstable}
pgfplotsset{compat=1.15}

makeatletter
deffoo@read#1#2foo@end{%
  gdeffoo@table{#2}%
  showfoo@table
}%
deffoo#1{%
    begingroup
    pgfplotstabletypeset[begin table=foo@read,end table=foo@end,
        set thousands separator={},
        sci e,
        verbatim
    ]{#1}%
    endgroup
}
deffoo@code#1{%
    begingroup
    pgfqkeys{/pgfplots/table/create col/quadratic regression}{#1}%
    pgfkeysgetvalue{/pgfplots/table/create col/quadratic regression/table}{pgfplotstable@table}%
    foo{pgfplotstable@table}%
    endgroup
}
pgfkeys{%
        /pgfplots/table/create col/quadratic regression/.code={foo@code{#1}},
        /pgfplots/table/create col/quadratic regression/.default=,%
        /pgfplots/table/create col/quadratic regression/x/.initial=,%
        /pgfplots/table/create col/quadratic regression/y/.initial=,%
        /pgfplots/table/create col/quadratic regression/table/.initial=%
}
makeatother

usepackage{filecontents}
begin{document}

begin{figure*}
  begin{tikzpicture}
    pgfplotstableread{
        param-0-univ-count param-1-n abstract-regression-quadratic-regression-cubic-real abstract-regression-quadratic-regression-cubic-sys abstract-regression-quadratic-regression-cubic-user close-abstract-regression-quadratic-regression-cubic-real close-abstract-regression-quadratic-regression-cubic-sys close-abstract-regression-quadratic-regression-cubic-user exact-regression-quadratic-regression-cubic-regression-linear-real exact-regression-quadratic-regression-cubic-regression-linear-sys exact-regression-quadratic-regression-cubic-regression-linear-user
        1 0 0. 0. 0. 0. 0. 0. 0. 0. 0.
        2 1 0. 0. 0. 0. 0. 0. 0. 0. 0.
        4 2 0. 0. 0. 0. 0. 0. 0. 0. 0.
        8 3 0.001 0. 0.001 0. 0. 0. 0. 0. 0.
        16 4 0.002 0.002 0. 0.001 0.001 0. 0. 0. 0.
        32 5 0.005 0. 0.004 0.003 0. 0.003 0.001 0. 0.001
        64 6 0.01 0.006 0.003 0.006 0.006 0. 0.003 0. 0.003
        128 7 0.068 0.004 0.063 0.06 0.004 0.056 0.007 0. 0.007
        256 8 0.036 0. 0.036 0.026 0. 0.026 0.009 0. 0.009
        512 9 0.104 0. 0.104 0.084 0. 0.084 0.019 0. 0.019
        1024 10 0.262 0.003 0.258 0.221 0.003 0.217 0.04 0. 0.04
        2048 11 0.798 0.003 0.794 0.692 0.003 0.688 0.105 0. 0.105
        4096 12 2.39 0.003 2.386 2.179 0. 2.179 0.211 0.003 0.207
        8192 13 8.301 0.016 8.285 7.866 0.012 7.853 0.434 0.003 0.43
        16384 14 54.838 0.031 54.805 53.947 0.015 53.93 0.89 0.015 0.875
    }{testdata}
    begin{axis}
        foo{testdata}%
    end{axis}
  end{tikzpicture}
end{figure*}
end{document}

This works as expected and displays

> foo@table=macro:
->param-0-univ-count&param-1-n&abstract-regression-quadratic-regression-cubic-r
eal&abstract-regression-quadratic-regression-cubic-sys&abstract-regression-quad
ratic-regression-cubic-user&close-abstract-regression-quadratic-regression-cubi
c-real&close-abstract-regression-quadratic-regression-cubic-sys&close-abstract-
regression-quadratic-regression-cubic-user&exact-regression-quadratic-regressio
n-cubic-regression-linear-real&exact-regression-quadratic-regression-cubic-regr
ession-linear-sys&exact-regression-quadratic-regression-cubic-regression-linear
-user1&0&0&0&0&0&0&0&0&0&02&1&0&0&0&0&0&0&0&0&04&2&0&0&0&0&0&0&0&0&08&3
&1e-3&0&1e-3&0&0&0&0&0&016&4&2e-3&2e-3&0&1e-3&1e-3&0&0&0&032&5&5e-3&0&4e-3&
3e-3&0&3e-3&1e-3&0&1e-364&6&1e-2&6e-3&3e-3&6e-3&6e-3&0&3e-3&0&3e-3128&7&6.8
e-2&4e-3&6.3e-2&6e-2&4e-3&5.6e-2&7e-3&0&7e-3256&8&3.6e-2&0&3.6e-2&2.6e-2&0&2.
6e-2&9e-3&0&9e-3512&9&0.1&0&0.1&8.4e-2&0&8.4e-2&1.9e-2&0&1.9e-21024&10&0.26
&3e-3&0.26&0.22&3e-3&0.22&4e-2&0&4e-22048&11&0.8&3e-3&0.79&0.69&3e-3&0.69&0.1
1&0&0.114096&12&2.39&3e-3&2.39&2.18&0&2.18&0.21&3e-3&0.218192&13&8.3&1.6e-2
&8.29&7.87&1.2e-2&7.85&0.43&3e-3&0.4316384&14&54.84&3.1e-2&54.81&53.95&1.5e-2
&53.93&0.89&1.5e-2&0.88.
foo@read ...gdef foo@table {#2}show foo@table

l.63         foo{testdata}
                            %
?

However, if I instead invoke the code via something like

addplot table[x=param-0-univ-count,y={create col/quadratic regression={y=abstract-regression-quadratic-regression-cubic-real}}]{testdata};

rather than foo{testdata}, then I instead get

! Package pgfkeys Error: I do not know the key '/tikz/set thousands separator',
 to which you passed '', and I am going to ignore it. Perhaps you misspelled it
.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.64 ...ratic-regression-cubic-real}}]{testdata};

?

What’s going wrong here, and how do I fix it?


Context for this question: I’m trying to leverage https://tex.stackexchange.com/a/568840/2066 (and earlier https://tex.stackexchange.com/a/234136/2066) to turn my code for adding regressions at https://github.com/pgf-tikz/pgfplots/issues/351 into code that more closely matches the linear regression interface.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP