Y 轴平方根缩放

Y 轴平方根缩放

由于数据的性质,我试图在 pgfplots 中创建我的数据的箱线图,并使用 Y 轴的平方根缩放。

这是我的代码:

\documentclass{article} 
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.statistics}
\pgfplotsset{compat=1.17}
\usepackage{filecontents}

\begin{filecontents*}{file.csv}
a,b,c,d,e
0.0,2.842170943040401e-14,0.0,0.02581787109375,1.8994026184082031
0.0,0.3329588710026492,0.75,0.02837371826171875,0.4414405822753906
0.0,0.15510184685969364,0.375,0.1663665771484375,0.199951171875
0.0,0.000375662574413127,0.0,0.2701606750488281,0.8085689544677734
0.0,1.4210854715202004e-14,0.0,0.03917694091796875,0.25116539001464844
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    boxplot/draw direction=y,
    ymin=0., ymax=64.,
    y coord trafo/.code={\pgfmathparse{sqrt{#1}}},  % Y-axis forward transform
    y coord inv trafo/.code={\pgfmathparse{#1^2}},  % Y-axis backward transform
    table/row sep=newline,
    table/col sep=comma
]
\addplot+[boxplot={draw position=1}, fill, draw=black, solid, mark=none] table [y=a] {file.csv};
\end{axis}
\end{tikzpicture} 
\end{document}

我收到了一条模棱两可的错误消息

This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./sqrt_plot.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18>
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgfplots/pgfplots.sty
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgfplots/pgfplots.revision.tex)
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-def/pdftex.def)))
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te
x
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-li
sts.tex))
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def
) (/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/pgf.revision.tex)))
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.c
ode.tex))
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-pdftex.d
ef
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-p
df.def)))
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.
code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.
code.tex)) (/usr/local/texlive/2021/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-cfg/color.cfg))
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex
)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.
tex
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic
.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigo
nometric.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.rando
m.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.compa
rison.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.
code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round
.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.
code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integ
erarithmetics.code.tex)))
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex)
) (/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfint.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.co
de.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconst
ruct.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage
.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.co
de.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicst
ate.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransform
ations.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.cod
e.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.c
ode.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathproce
ssing.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.co
de.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.cod
e.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.cod
e.tex
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal.
code.tex))
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.co
de.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretranspare
ncy.code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns.
code.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/basiclayer/pgfcorerdf.code.
tex)))
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.cod
e.tex)
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.
tex)
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-0-65.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-1-18.sty))
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/utilities/pgffor.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/pgf/utilities/pgfkeys.sty
(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex)
./sqrt_plot.tex:26: Missing \endcsname inserted.
<to be read again> 
                   \relax 
l.26 ... solid, mark=none] table [y=b] {file.csv};
                                                  
?                                      

这似乎是坐标缩放的问题。但是,当我用\addplot以下内容替换时,它就可以正常工作。

\addplot { x^2 };  % this works

该问题一定与坐标变换与 CSV 绘图数据结合时有关。

有人能帮帮我吗?

答案1

在某些时候,它与非数字一起boxplot使用。-否则它似乎有效。我从这里复制了:y coord trafoisPGFNumberhttps://tex.stackexchange.com/a/463819/8650#1并在转换之前用它来测试是否是一个数字。

按平方根比例绘制的工作箱线图:

\documentclass[tikz, border=1cm]{standalone} 
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.statistics}
\newcommand{\isPGFNumber}[3]{% \isPGFNumber{<Number>}{<True>}{<False>}
    \begingroup
    \pgfkeys{/pgf/fpu/handlers/invalid number/.code={}}%
    \pgfmathfloatparsenumber{#1}%
    \global\pgfmathfloatgetflagstomacro\pgfmathresult\pgfFloatParseFlag%
    \endgroup
    \ifnum\pgfFloatParseFlag=3%
        #3%
    \else%
        #2%
    \fi%
}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin=0., ymax=64.,
boxplot/draw direction=y,
y coord trafo/.code={\isPGFNumber{#1}{\pgfmathparse{sqrt(#1)}}{}},
y coord inv trafo/.code={\pgfmathparse{#1^2}},
]
\addplot+[boxplot]  table[row sep=\\,y index=0] {4\\ 4\\ 4\\ 36\\ 36\\ 36\\};
\addplot {x^2};
\end{axis}
\end{tikzpicture} 
\end{document}

具有平方根刻度和两个图的图形

相关内容