![散点图 - 从数据和自定义颜色图中标记绝对大小](https://linux22.com/image/357309/%E6%95%A3%E7%82%B9%E5%9B%BE%20-%20%E4%BB%8E%E6%95%B0%E6%8D%AE%E5%92%8C%E8%87%AA%E5%AE%9A%E4%B9%89%E9%A2%9C%E8%89%B2%E5%9B%BE%E4%B8%AD%E6%A0%87%E8%AE%B0%E7%BB%9D%E5%AF%B9%E5%A4%A7%E5%B0%8F.png)
我正在尝试实现一个散点图,该散点图可以根据其绝对值自动缩放标记。我不想使用,\pgfplotspointmetatransformed
而是使用\pgfplotspointmeta
,因为我需要将其与另一个图进行比较,尽管我做不到这一点……
此外,我尝试创建一个颜色图,该颜色图从 z > 0 的颜色范围和 z < 0 的不同颜色范围进行映射。所以你会立即注意到一个值是负数还是正数 - 虽然我有点困惑,所以设置限制的方式是,它在 0 时从红色变为蓝色,因为我已经在使用元数据来表示大小...
\pgfplotstableread{
A B C
0 5 -10
0.5 2 0
1 7 5
1.5 11 20
}\mytable
\begin{tikzpicture}
\pgfplotsset{
colormap={test}{[2pt]
rgb255(0pt)=(255, 200, 0);
rgb255(500pt)=(255, 75, 0);
rgb255(502pt)=(0, 100, 255);
rgb255(1000pt)=(0, 255, 255)
}
}
\begin{axis}[
colorbar
]
\addplot[
scatter,
only marks,
scatter src=explicit,
mark=*,
scatter/use mapped color={
draw=mapped color,
fill=mapped color,
},
scatter/@pre marker code/.append style=
{/tikz/mark size={.6pt+abs(\pgfplotspointmetatransformed/200)}}]
table[meta expr=abs(\thisrow{C})] {\mytable};
\end{axis}
\end{tikzpicture}
我很高兴得到提示,
谢谢
答案1
我不太确定我是否理解了你的问题。你的意思是类似下面的内容吗?
% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{
colormap={test}{[2pt]
rgb255(0pt)=(255, 200, 0);
rgb255(500pt)=(255, 75, 0);
rgb255(502pt)=(0, 100, 255);
rgb255(1000pt)=(0, 255, 255)
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colorbar,
% because you want the color change at zero but don't have "symmetric"
% data, you have to give the `point meta min' and `point meta max'
% values manually
point meta min=-20,
point meta max=20,
]
\addplot[
scatter,
only marks,
scatter src=explicit,
mark=*,
scatter/use mapped color={
draw=mapped color,
fill=mapped color,
},
% store the (original) of "C" in a macro ...
visualization depends on={\thisrow{C} \as \perpointmarksize},
scatter/@pre marker code/.append style={
% ... and use this macro here
% (please note that I have changed the values a bit )
/tikz/mark size={1pt+abs(\perpointmarksize/5)}
},
% because of a bug in PGFPlots (<https://sourceforge.net/p/pgfplots/bugs/109/>)
% you have to give the table explicitly like here or in a file to not get an
% error message
% (it is not allowed to give the table as a command)
] table [meta=C] {
A B C
0 5 -10
0.5 2 0
1 7 5
1.5 11 20
};
\end{axis}
\end{tikzpicture}
\end{document}