透明脈衝(ycomb)與pgfplots重疊?

透明脈衝(ycomb)與pgfplots重疊?

考慮以下 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 呈現為(點擊查看全尺寸圖片):

測試-1.png

啟用「% global」不透明度後,pdf 將呈現為:

測試-2.png

...然而,我想要的是“衝動”是透明的,因此當它們重疊時它們會獲得更強烈的顏色- 並且上面的圖像都沒有顯示:全局的是,嗯,全局的- 而“局部的” “應用於標記樣式的一項似乎被忽略了?

另外,有什麼辦法可以讓脈衝的標記(圓圈)完全填滿嗎? (如果仔細觀察全尺寸影像,看起來裡面好像有個洞)

有什麼辦法可以實現我想要的嗎?日誌檔說:

軟體包: 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}
...

....輸出是:

測試-3.png

我留下“僅標記”樣式只是為了更容易對重疊顏色進行視覺比較。現在唯一讓我煩惱的是圓形標記周圍有明顯的筆劃,但這沒什麼大不了的...

相關內容