我想打印散点图并根据数据文件中的列为节点着色。问题是,point meta
已经用于其他数据。这是点的类别,无论是 ONE 还是 TWO,它都用于标记。此外,节点已贴上标签。
那么该如何做呢?
工作示例:
\input{include_filename} % defines \outputfile, written by batchjob
\documentclass[border=5pt,convert]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.10}
\begin{document}%
\setlength{\textwidth}{500pt}%
\setlength{\linewidth}{500pt}%
\begin{tikzpicture}
\begin{axis}[]
\addplot+[
scatter, only marks,
point meta=explicit symbolic,
scatter/classes={
ONE={mark=*,mark color=\myerror},% <-- here is the problem
TWO={mark=triangle*,mark color=\myerror}},%
nodes near coords*={\pgfmathprintnumber[int detect]{\myindex}},
visualization depends on={\thisrow{error} \as \myerror},
visualization depends on={\thisrow{index} \as \myindex},
]
table[meta=partition]{\outputfile};
\end{axis}
\end{tikzpicture}
\end{document}
数据文件如下所示:
x y error partition index
-86 -27 0 ONE 3
error
可能是一个相当大的负数。例如 -35547923
答案1
如果我理解正确的话,你的标记颜色应该取自颜色图,对吗?
我认为一个简单的解决方案是使用error
作为的输入point meta
。这样,您就可以免费将映射到颜色图中。当然,我们需要使用不同的键来满足。我的想法是,我们在读取之前scatter/classes
简单地交换 的值:point meta
scatter/classes
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}%
\begin{tikzpicture}
\begin{axis}[]
\addplot+[
scatter, only marks,
point meta=\thisrow{error},
% use this key merely to define 'mapped color' based on the error
% value. The '{}' overrides the default 'draw' and 'fill' options
% of 'use mapped color':
scatter/use mapped color={},
% now, append code which RESETS \pgfplotspointmeta to \partition.
% This will become the input to 'scatter/classes*':
scatter/@pre marker code/.append code={%
\let\pgfplotspointmeta=\partition
},%
scatter/classes*={
ONE={mark=*,mapped color},%
TWO={mark=triangle*,mapped color}},%
nodes near coords*={\pgfmathprintnumber[int detect]{\myindex}},
%
% use 'value ' here : partition should not be parsed as number.
visualization depends on={value \thisrow{partition} \as \partition},
visualization depends on={\thisrow{index} \as \myindex},
]
table[meta=partition]{
x y error partition index
-86 -27 0 ONE 3
-0 -100 -15547923 ONE 42
50 -200 -35547923 TWO 4
};
\end{axis}
\end{tikzpicture}
\end{document}
和 的作用/.append code
相同:它将代码附加到。由于这些是按指定顺序应用的,我们可以在中间重置点元数据。scatter/classes*
nodes near coords*
pre marker code