勾勒出绘制的图表?

勾勒出绘制的图表?

要用白色勾勒出路径轮廓,通常先将路径画大一点,然后填充白色,再将填充黑色的原始路径复制过来覆盖。这样可以更好地将其与背景区分开来。

但这在 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}

相关内容