4

How do I replace the blue backgrounds as indicated in the picture with a diagonal and grid pattern respectively?

I currently can't find a neat solution for my kind of graph.

Code

\begin{tikzpicture}
    \begin{axis}[
        ybar,
        bar width=1.0cm,
        enlargelimits=0.75,
        width=7.5cm, 
        height=6cm,
        xlabel={Predictive models}, ylabel style={align=center},
        ylabel={Predicitve accuracy (\%)},
        symbolic x coords={ensemble voting, lung cancer calculator},
        xtick=data, 
        xticklabel style={text width=2cm, align=center}
    ]
    \addplot coordinates {
        (lung cancer calculator,91.2)
        (ensemble voting,91.4)
    };
    \end{axis}
\end{tikzpicture}

Output

output image

3

You can use TikZ drawing options in \addplot options.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{patterns}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        ybar,
        bar width=1.0cm,
        enlargelimits=0.75,
        width=7.5cm, 
        height=6cm,
        xlabel={Predictive models}, ylabel style={align=center},
        ylabel={Predicitve accuracy (\%)},
        symbolic x coords={ensemble voting, lung cancer calculator},
        xtick=data, 
        xticklabel style={text width=2cm, align=center}
    ]
    \addplot[pattern=crosshatch] coordinates {
        (lung cancer calculator,91.2)
        (ensemble voting,91.4)
    };
\end{axis}
\end{tikzpicture}

\end{document}
  • how do I give the two bars different patterns? – Saggy Manatee And Swan Folk Oct 2 '13 at 3:07
  • 1
    @thekalaban You can use two \addplot commands one for each coordinate with different pattern. – percusse Oct 2 '13 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.