我正在使用point meta
数据根据输入数据文件最后一列的值来设置绘制数据的线条颜色data.csv
:
% !TeX program=lualatex
\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotstableset{col sep=comma}
\pgfplotstableread{cat.csv}{\data} % see below for content of cat.csv
\begin{axis}[
xmin=0,
xmax=5,
xmode=log,
]
\addplot+ [line width=1pt,mark=none,mesh,point meta=explicit]
table [x index=1,y index=2,meta index=3] {\data};
\end{axis}
\end{tikzpicture}
\end{document}
数据point meta
(根据 的最后一列cat.csv
)要么0.0
要么1.0
。尽管如此,我得到的并不是只有两种线条颜色,而是这样的:
我的数据只提供两种颜色,为什么也会有一些黄色部分?
这是我的逗号分隔的输入数据文件的内容cat.csv
:
1.980000000000000000e+02,3.039999959999999835e+00,-2.097669999999999830e-03,1.000000000000000000e+00
1.990000000000000000e+02,3.069999929999999821e+00,-2.095430000000000122e-03,1.000000000000000000e+00
2.000000000000000000e+02,3.099999899999999808e+00,-2.093180000000000041e-03,1.000000000000000000e+00
2.010000000000000000e+02,3.130000110000000113e+00,-2.090920000000000018e-03,1.000000000000000000e+00
2.020000000000000000e+02,3.160000090000000039e+00,-2.088650000000000055e-03,1.000000000000000000e+00
2.030000000000000000e+02,3.190000060000000026e+00,-2.086339999999999896e-03,1.000000000000000000e+00
2.040000000000000000e+02,3.220000030000000013e+00,-2.084030000000000171e-03,1.000000000000000000e+00
2.050000000000000000e+02,3.250000000000000000e+00,-2.081700000000000130e-03,1.000000000000000000e+00
2.060000000000000000e+02,3.279999969999999987e+00,-2.079370000000000090e-03,1.000000000000000000e+00
2.070000000000000000e+02,3.309999939999999974e+00,-2.077040000000000049e-03,1.000000000000000000e+00
2.080000000000000000e+02,3.339999909999999961e+00,-2.074700000000000068e-03,1.000000000000000000e+00
2.090000000000000000e+02,3.369999889999999887e+00,-1.954609999999999854e-03,0.000000000000000000e+00
2.100000000000000000e+02,3.400000100000000192e+00,-1.829920000000000071e-03,0.000000000000000000e+00
2.110000000000000000e+02,3.430000070000000179e+00,-1.704299999999999956e-03,0.000000000000000000e+00
2.120000000000000000e+02,3.460000040000000165e+00,-1.580479999999999993e-03,0.000000000000000000e+00
2.130000000000000000e+02,3.490000010000000152e+00,-1.468619999999999908e-03,0.000000000000000000e+00
2.140000000000000000e+02,3.519999980000000139e+00,-1.368470000000000103e-03,0.000000000000000000e+00
2.150000000000000000e+02,3.549999950000000126e+00,-1.278829999999999897e-03,0.000000000000000000e+00
2.160000000000000000e+02,3.579999920000000113e+00,-1.198650000000000106e-03,0.000000000000000000e+00
2.170000000000000000e+02,3.609999900000000039e+00,-1.126990000000000023e-03,0.000000000000000000e+00
2.180000000000000000e+02,3.640000099999999961e+00,-1.063020000000000024e-03,0.000000000000000000e+00
2.190000000000000000e+02,3.670000079999999887e+00,-1.005980000000000069e-03,0.000000000000000000e+00
2.200000000000000000e+02,3.700000049999999874e+00,-9.552099999999999567e-04,0.000000000000000000e+00
2.210000000000000000e+02,3.730000019999999861e+00,-9.100999999999999498e-04,0.000000000000000000e+00
2.220000000000000000e+02,3.759999989999999848e+00,-8.700999999999999533e-04,0.000000000000000000e+00
2.230000000000000000e+02,3.789999959999999835e+00,-8.347299999999999989e-04,0.000000000000000000e+00
2.240000000000000000e+02,3.819999929999999821e+00,-8.035600000000000381e-04,0.000000000000000000e+00
2.250000000000000000e+02,3.849999899999999808e+00,-7.761899999999999529e-04,0.000000000000000000e+00
2.260000000000000000e+02,3.880000110000000113e+00,-7.522499999999999890e-04,0.000000000000000000e+00
2.270000000000000000e+02,3.910000090000000039e+00,-7.314399999999999765e-04,0.000000000000000000e+00
2.280000000000000000e+02,3.940000060000000026e+00,-7.134700000000000113e-04,0.000000000000000000e+00
2.290000000000000000e+02,3.970000030000000013e+00,-6.980600000000000216e-04,0.000000000000000000e+00
2.300000000000000000e+02,4.000000000000000000e+00,-6.849999999999999535e-04,0.000000000000000000e+00
2.310000000000000000e+02,4.030000209999999861e+00,-6.740500000000000397e-04,0.000000000000000000e+00
2.320000000000000000e+02,4.059999939999999974e+00,-6.650399999999999888e-04,0.000000000000000000e+00
2.330000000000000000e+02,4.090000149999999834e+00,-6.577900000000000023e-04,0.000000000000000000e+00
2.340000000000000000e+02,4.119999889999999887e+00,-6.521300000000000057e-04,0.000000000000000000e+00
2.350000000000000000e+02,4.150000099999999748e+00,-6.479300000000000120e-04,0.000000000000000000e+00
2.360000000000000000e+02,4.179999829999999861e+00,-6.450499999999999854e-04,0.000000000000000000e+00
2.370000000000000000e+02,4.210000039999999721e+00,-6.433699999999999879e-04,0.000000000000000000e+00
2.380000000000000000e+02,4.239999769999999835e+00,-6.427899999999999630e-04,0.000000000000000000e+00
2.390000000000000000e+02,4.269999979999999695e+00,-6.427200000000000534e-04,1.000000000000000000e+00
2.400000000000000000e+02,4.300000190000000444e+00,-6.426500000000000355e-04,1.000000000000000000e+00
2.410000000000000000e+02,4.329999919999999669e+00,-6.425800000000000175e-04,1.000000000000000000e+00
2.420000000000000000e+02,4.360000130000000418e+00,-6.425200000000000486e-04,1.000000000000000000e+00
2.430000000000000000e+02,4.389999869999999582e+00,-6.424700000000000202e-04,1.000000000000000000e+00
2.440000000000000000e+02,4.420000080000000331e+00,-6.424199999999999919e-04,1.000000000000000000e+00
2.450000000000000000e+02,4.449999809999999556e+00,-6.423699999999999636e-04,1.000000000000000000e+00
2.460000000000000000e+02,4.480000020000000305e+00,-6.423299999999999843e-04,1.000000000000000000e+00
2.470000000000000000e+02,4.510000230000000165e+00,-6.422900000000000050e-04,1.000000000000000000e+00
答案1
解决方案是使用shader=flat corner
。此参数用于所有基于颜色数据的绘图,以及shader=flat
端点的默认平均值。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\pgfplotstableset{col sep=comma}
\pgfplotstableread{cat.csv}{\data} % see below for content of cat.csv
\begin{axis}[
xmin=0,
xmax=5,
xmode=log,
]
\addplot+ [line width=1pt,mark=none,mesh,point meta=explicit,shader=flat corner]
table [x index=1,y index=2,meta index=3] {\data};
\end{axis}
\end{tikzpicture}
\end{document}