考虑以下 MWE:
\documentclass[%
12pt,
journal,
twoside,
draftcls,
letterpaper,
]{IEEEtran}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usetikzlibrary{intersections} %% named intersections "I do not know the key '/tikz/name path global'"
\begin{document}
\pgfplotstableread[col sep=&,row sep=\\]{
0.0159779999812599 & 0.00398599999607541 \\
0.0240009999834001 & 0.00802300000214018 \\
0.0240489999996498 & 4.80000162497163e-05 \\
0.0280280000006314 & 0.00397900000098161 \\
}\mytable
\begin{tikzpicture}
\begin{scope}
\begin{axis}[
title={\small my data},
title style={at={(0.5,0.9)},anchor=center},
clip=true,
axis x line=middle,
axis y line=middle,
y axis line style=-,
xmin = 2e-3,
xmax = 38e-3,
ymin = 0,
ymax = 1.5,
xlabel={$t$\,[ms]},
xlabel style={at={(axis description cs:1.01,+0.0)},anchor=west},
ylabel={}, %{$U$\,[V]},
ylabel style={at={(axis description cs:-0.02,1.01)},anchor=south},
xtick=data,
scaled x ticks=base 10:3,
xtick scale label code/.code={},
x tick label style={
rotate=-45,
anchor=west,
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=3,
},
ymajorticks=false,
yminorticks=false,
tick label style={font=\small,},
legend cell align=left,
legend pos=outer north east,
]
\addplot[
name path global=afunc,
ycomb,
draw=black,
% opacity=0.2, % global
mark=*, mark options={
draw=black,
fill=black,
opacity=0.2, % on mark
},
line width=2pt,
]
table[x index = 0,y expr=1] \mytable ;
\end{axis}
\end{scope}
\end{tikzpicture}
\end{document}
使用原有的代码,evince
将 pdf 呈现为(单击可查看完整尺寸的图像):
启用“%global”不透明度后,pdf 呈现为:
...但是,我想要的是“脉冲”是透明的,所以当它们重叠时它们会获得更强烈的颜色 - 并且上面的图像都没有显示这一点:全局的就是全局的 - 而应用于标记样式的“局部”的似乎被忽略了?
另外,有什么方法可以让脉冲的标记(圆圈)完全填满?(如果仔细观察全尺寸图像,看起来里面好像有一个洞)
有什么方法可以实现我想要的吗?日志文件显示:
包:pgfplots 2011/12/29 v1.5.1(git show 1.5.1-4-g53e640f)
答案1
好吧,我找到了一种可行的办法:首先,我尝试了ybar
风格,它有点类似 - 但它似乎也将不透明度/透明度应用于整个图表 - 而不是单个条形图/线条。
因此,我尝试循环遍历表格数据并绘制具有不透明度的单独线条 - 最后似乎成功了;上述 MWE 中的相关变化是:
...
\usepackage{pgfplotstable}
...
]
\def\opac{0.4}
\addplot[
name path global=afunc,
only marks, %ycomb,
draw=none, %black,
%opacity=\opac, % global
mark=*, mark options={
draw=none, %black,
%fill=black,
opacity=\opac, % on mark; both stroke and fill (and stroke will overlap fill - twice the opacity!? even with draw=none?)
},
%line width=2pt, % also changes the line around the mark!
]
table[x index = 0,y expr=1] \mytable ;
% \addplot[
% name path global=afuncb,
% ybar,
% bar width=2pt,
% %fill=black,
% %draw=none,
% opacity=0.4,
% ]
% table[x index = 0,y expr=1] \mytable ;
\pgfplotstableforeachcolumnelement{0}\of\mytable\as\cx{%
% \node{I have now cell element ‘\cx’ at row index ‘\pgfplotstablerow’;\par};
\edef\temp{ %
\noexpand\draw[%
line width=2pt, %semithick,
draw=black,%
fill=none,%
opacity=\opac,%
] ({axis cs:\cx,0}) -- ({axis cs:\cx,1}); %
}
\temp
}
\end{axis}
...
...输出为:
我保留了“仅标记”样式,只是为了更容易地对叠加的颜色进行视觉比较。现在唯一困扰我的是圆形标记周围有明显的笔触,但这没什么大不了的……