1

enter image description here

I want to implement the top answer in this to colour and hatch bars as above, and compiled exactly the same code.

\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}

However, I got this. Only the bottom was hatched.

enter image description here

I also tried every path from the same answer.

\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}

Now, the bottom is gone.

enter image description here

How can I get the same result as the original article? Since the source code is exactly the same, I suspect this is to do with my latex version, which is as below.

$ 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
Kaz
  • 23
  • 1
    Welcome. // Please understand: without adding >> your << code to the question, this question will probably soon be closed: we can't know, what you did or didn't do ... – MS-SPO May 29 '23 at 08:47

1 Answers1

2

With your MWE (Minimal Working Example) I can't reproduce your image. It works fine (with pgfplots version 1.18, compiled by 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}

enter image description here

Zarko
  • 296,517
  • I've found that my pgfplot version was 1.17, so will give 1.18 a go and see how it goes. Cheers. – Kaz May 30 '23 at 23:34