勾勒出繪製的圖表?

勾勒出繪製的圖表?

要用白色勾勒出路徑,通常將路徑繪製得更大並用白色填充,然後將用黑色填充的原始路徑複製到其上。這是為了更好地將其與背景分開。

但這當然在 pgfplots 中不起作用。如果\addplot圖形的一個副本為白色,且line width=大於預期圖形,則原始圖形會發生移動,因此它們無法重疊以給出每個(黑色)條形的白色輪廓。

問題1:除了黑色輪廓(保持黑色)之外,如何讓 pgfplots 以白色輪廓顯示條形圖中的每個條形?

問題2(已經在評論中回答):第一個條形和 Y 軸之間的水平距離是如何縮放的? )

例如,如何做到這一切:

\documentclass{standalone}\usepackage{pgfplots,tikz}
\begin{document}\begin{tikzpicture}\pgfplotsset{%
every axis legend/.append style={at={(0.9,0.7)},anchor=south east}}%
\draw[draw=none,fill=black!20]rectangle(13.4,13.4);
\begin{axis}[title={},grid=major,scaled y ticks=false,
bar width=12.34pt,line width=3.2pt,%
enlarge x limits={true,abs value=0.64},
width=428pt,x tick style={line width=2.4pt,draw=black},%
height=428pt,y tick style={line width=2.4pt,draw=black},%
ybar=8pt,%BAR SEPARATION
yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},%
xtick=\empty,xtick={1,...,3},xticklabels={%
    \textbf{A},%
    \textbf{B},%
    \textbf{C},%
},legend style={inner xsep=8pt,inner ysep=4pt,line width=2pt,draw=none,minimum height=22pt,column sep=4pt},% remove this to show the legend border
legend image code/.code={\draw[#1](-6pt,-6pt)rectangle(6pt,6pt);}%
]%
\addplot[fill=blue60!,draw=black,
point meta=y,
every node near coord/.style={inner ysep=8pt},
error bars/.cd,y dir=both,
y explicit]table[y error=error]{%
x   y       error    label
1   19.9    2           1
2   38.6    3           2
3   35.2    3           3
};%LEGEND
\legend{\makebox[64pt]{\raisebox{-2pt}{MyLabelGoesHereYes}},}
\end{axis}\end{tikzpicture}\end{document}

編輯:也許可以透過裝飾來完成?

答案1

您可以添加preaction={draw=white, line width=5pt}選項\addplot [...]以獲得白色輪廓:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    axis background/.style={fill=gray},
    axis on top
]
\addplot [fill=yellow, draw=black, very thick, preaction={draw=white, line width=5pt}] table {%
x   y
1   19.9
2   38.6
3   35.2
};
\end{axis}
\end{tikzpicture}
\end{document}

相關內容