我有这个代码:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{data.txt}
cola colb
+5.96596689e-01 +5.68950232e-01
+7.81573637e-01 +8.05102869e-01
+2.84382101e+00 +2.84187665e+00
+1.99704934e+00 +1.96129272e+00
+7.93205955e-01 +7.93202553e-01
+6.78986662e-01 +6.88970504e-01
+1.59626453e+00 +1.58217230e+00
+1.42671590e+00 +1.40128993e+00
+6.53091850e-01 +6.42550503e-01
+1.21697307e+00 +1.23192720e+00
+4.20476789e-01 +4.10997882e-01
+1.50696395e+00 +1.46977556e+00
+9.45266918e-01 +9.36188931e-01
+9.67830038e-01 +9.27234451e-01
+5.86247930e-01 +5.97340361e-01
+1.14913605e+00 +1.12917871e+00
+1.49166120e+00 +1.46676005e+00
+1.24503883e+00 +1.28617548e+00
+1.09749011e+00 +1.05883686e+00
\end{filecontents}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
cycle list = {{blue,fill=blue!70!green!30!white,mark=none},},
]
\addplot+[hist={data=x,bins=6}] table [x=cola] {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}
cola
我想制作和之间比率的直方图colb
,但我无法做到这一点。我只能制作单列的直方图:
我想计算 LaTeX 中线条之间的比例,因为该文件data.txt
是由外部程序自动生成的,如果 LaTeX 可以为我计算的话会更容易。
谢谢!
答案1
好问题!我觉得你正在寻找
据此您可以非常轻松地使用数据列的表达式。
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
cola colb
+5.96596689e-01 +5.68950232e-01
+7.81573637e-01 +8.05102869e-01
+2.84382101e+00 +2.84187665e+00
+1.99704934e+00 +1.96129272e+00
+7.93205955e-01 +7.93202553e-01
+6.78986662e-01 +6.88970504e-01
+1.59626453e+00 +1.58217230e+00
+1.42671590e+00 +1.40128993e+00
+6.53091850e-01 +6.42550503e-01
+1.21697307e+00 +1.23192720e+00
+4.20476789e-01 +4.10997882e-01
+1.50696395e+00 +1.46977556e+00
+9.45266918e-01 +9.36188931e-01
+9.67830038e-01 +9.27234451e-01
+5.86247930e-01 +5.97340361e-01
+1.14913605e+00 +1.12917871e+00
+1.49166120e+00 +1.46676005e+00
+1.24503883e+00 +1.28617548e+00
+1.09749011e+00 +1.05883686e+00
\end{filecontents*}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[cycle list = {{blue,fill=blue!70!green!30!white,mark=none},}]
\addplot+[hist={data=x/y,bins=6}] table [x=cola,y=colb] {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}