在 PGF 三元图中使用数据文件

在 PGF 三元图中使用数据文件

我想绘制三元图,我有一组包含 4 个不同值的数据集。3 个 vol.% 用于在图中表示点,另一个是这些浓度下的特定折射率。折射率应为图上该点的一个节点(见图)。

我设法编写了代码,但只有当我将整个数据集放入代码中时它才有效。

\documentclass[border=15mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots, siunitx, chemformula}
%%
\usepgfplotslibrary{ternary}
\pgfplotsset{compat=1.16}
%%
\usepackage{sfmath}
\begin{document}
\begin{tikzpicture}
  \begin{ternaryaxis}[
    colorbar, 
    colormap/jet,
    xlabel = vol.\%(\ch{H2O}),
    ylabel = vol.\%(\ch{C2H5OH}),
    zlabel = vol.\%(\ch{CHCl3}),
    grid = both,
    label style = {sloped},
    colorbar sampled,
    colorbar style={
        title={$n_D/\text{a.u}$},    
        samples=75,                  
        width=15,                   
        height=180,                 
        point meta min=1.330, 
        point meta max=1.440, 
        scaled y ticks = false,
        ytick = {1.330, 1.340, ..., 1.440},
        yticklabel={
    \pgfkeys{/pgf/fpu=true, /pgf/fpu/output format=fixed}
    \pgfmathparse{\tick}
            \num[
                round-integer-to-decimal = true,
                round-mode = places,
                round-precision = 3,
            ]{\pgfmathresult}
        },
        yticklabel style={
            text width=3em,       
            align=right,        
        }
    }
  ]
   \addplot3+[only marks, 
   point meta=\thisrow{refindex},
   nodes near coords*={\tiny{\pgfmathprintnumber\refindex}},
  visualization depends on={\thisrow{refindex} \as \refindex} 
  ] 
  table[x = volPercentC, y = volPercentA, z = volPercentB] {
        volPercentA         volPercentB         volPercentC         refindex
        0.7                 0.0142857142857143  0.285714285714286   1.3498
        0.615384615384615   0.0256410256410256  0.358974358974359   1.3542
        0.583850931677019   0.0372670807453416  0.37888198757764    1.3564
        0.529411764705882   0.0588235294117647  0.411764705882353   1.3589
        0.421052631578947   0.105263157894737   0.473684210526316   1.364
        0.3                 0.2                 0.5                 1.3732
        0.2                 0.3                 0.5                 1.3828
        0.111111111111111   0.444444444444444   0.444444444444444   1.3946
        0.0625              0.5625              0.375               1.405
        0.0422535211267606  0.661971830985915   0.295774647887324   1.4129
        0.0285714285714286  0.685714285714286   0.285714285714286   1.4151
        0.0161290322580645  0.790322580645161   0.193548387096774   1.4257
  };
  \end{ternaryaxis}
\end{tikzpicture}
\end{document}

对于如此小的数据集,这可能足够了,但对于较大的数据集则不然。我排除了数据.txt并将代码更改为:

\documentclass[border=15mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots, siunitx, chemformula}
%%
\usepgfplotslibrary{ternary}
\pgfplotsset{compat=1.16}
%%
\usepackage{sfmath}
\begin{document}
\begin{tikzpicture}
  \begin{ternaryaxis}[
    colorbar, 
    colormap/jet,
    xlabel = vol.\%(\ch{H2O}),
    ylabel = vol.\%(\ch{C2H5OH}),
    zlabel = vol.\%(\ch{CHCl3}),
    grid = both,
    label style = {sloped},
    colorbar sampled,
    colorbar style={
        title={$n_D/\text{a.u}$},    
        samples=75,                  
        width=15,                   
        height=180,                 
        point meta min=1.330, 
        point meta max=1.440, 
        scaled y ticks = false,
        ytick = {1.330, 1.340, ..., 1.440},
        yticklabel={
    \pgfkeys{/pgf/fpu=true, /pgf/fpu/output format=fixed}
    \pgfmathparse{\tick}
            \num[
                round-integer-to-decimal = true,
                round-mode = places,
                round-precision = 3,
            ]{\pgfmathresult}
        },
        yticklabel style={
            text width=3em,       
            align=right,        
        }
    }
  ]
   \addplot3+[only marks, 
   point meta=\thisrow{refindex},
   nodes near coords*={\tiny{\pgfmathprintnumber\refindex}},
  visualization depends on={\thisrow{refindex} \as \refindex} 
  ] 
  table[x = volPercentC, y = volPercentA, z = volPercentB] {
        data.txt
  };
  \end{ternaryaxis}
\end{tikzpicture}
\end{document}

通常情况下,对于正常的散点图,它都是这样工作的。但不幸的是,在这种情况下,我的日志是血红色的,没有绘制任何数据。

输出

谢谢你的协助。

问候 FH

相关内容