使用示例页面 288pgfplots 图层手册,我不能使用除 之外的其他风格mark size
。
% Preamble: \pgfplotsset{width=7cm,compat=1.5.1}
\begin{tikzpicture}
\begin{axis}
\addplot+[
scatter,
scatter src=y,
samples=40,
visualization depends on={5*cos(deg(x)) \as \perpointmarksize},
scatter/@pre marker code/.append style={
/tikz/mark size=\perpointmarksize,
/tikz/opacity=\perpointmarksize % <-- this line has no effect
}
]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
是我遗漏了什么还是库中存在错误?
答案1
不,没有错误。按照手册,必须scatter/@pre marker code/.code
以略有不同的方式使用,更重要的是,确保不透明度取值在 0 到 1 之间。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[
scatter,
scatter src=y,
samples=40,
visualization depends on={5*cos(deg(x)) \as \perpointmarksize},
scatter/@pre marker code/.code={
\pgfplotscolormapdefinemappedcolor\pgfplotspointmetatransformed
\pgfmathsetmacro{\myopacity}{max(0,min(1,1+\perpointmarksize/5))}
\def\markopts{mark size=\perpointmarksize,%
mapped color,
opacity=\myopacity}
\expandafter\scope\expandafter[\markopts]
},
scatter/@post marker code/.code={
\endscope
},
]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}