我想实现最佳答案这对条形图进行着色和阴影处理,如上所示,然后编译完全相同的代码。
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar, samples=10, enlarge y limits=upper, ymin=0]
\addplot +[
black,
fill=yellow,
postaction={
pattern=north east lines
}
]{rnd};
\end{axis}
\end{tikzpicture}
\end{document}
但我得到了这个。只有底部有阴影。
我也尝试了相同答案的每条路径。
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{patterns}
\makeatletter
\tikzset{nomorepostaction/.code=\let\tikz@postactions\pgfutil@empty}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar, samples=10]
\addplot +[
black,
fill=yellow,
every path/.style={
postaction={
nomorepostaction,
pattern=north east lines
}
}
]{rnd};
\end{axis}
\end{tikzpicture}
\end{document}
如今,底部已经消失。
我怎样才能得到与原始文章相同的结果?由于源代码完全相同,我怀疑这与我的 latex 版本有关,如下所示。
$ pdflatex --version
pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2021)
kpathsea version 6.3.3
Copyright 2021 Han The Thanh (pdfTeX) et al.
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.37; using libpng 1.6.37
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.03
答案1
使用您的 MWE(最小工作示例),我无法重现您的图像。它运行良好(使用 pgfplots 版本 1.18,由 编译pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 23.5) (preloaded format=pdflatex.fmt)
):
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} % <---
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
samples=10,
enlarge y limits=upper,
ymin=0]
\addplot +[black, fill=yellow,
postaction={pattern=north east lines}
] {rnd};
\end{axis}
\end{tikzpicture}
\end{document}