0

I am kindly requesting for assistance on how to have the color of my histogram bars alternate between blue and orange. Currently the bars all have the same color which is something I do not like. Below is my MWE:

\documentclass{article}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.16,width=\textwidth,height=12cm}
    
    \begin{document}

    \begin{tikzpicture}
        \begin{axis}[
            ybar,bar width=5cm,ylabel={Number of claims},yticklabel=$\mathsf{\pgfmathprintnumber{\tick}}$,
            xticklabel=$\mathsf{\pgfmathprintnumber{\tick}}$,xlabel={Range of Claim Amounts},               
            ymin=0, ymax=2200,
            xtick distance=200,
            minor y tick num = 3,
            area style,
            ]
            \addplot+[ybar interval,mark=no] plot coordinates { (0, 800) (200, 1400) (400, 2100) (600, 1800) (800, 1200) (1000, 900) (1200, 300) (1400, 100) (1600, 0)};
        \end{axis}
    \end{tikzpicture}

\end{document}

1 Answer 1

1
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fadings}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=\textwidth, height=12cm,
xlabel={Range of Claim Amounts}, ylabel={Number of claims}, 
xmin=0, xmax=1600,
ymin=0, ymax=2200,
enlarge x limits,
xtick distance=200,
minor y tick num=3,
/pgf/number format/1000 sep={\,},
]
\addplot[
fill=blue!30,
ybar, bar width=200, bar shift=100,
] plot coordinates { (0,800) (400,2100) (800,1200) (1200,300)};
\addplot[
fill=orange!30,
ybar, bar width=200, bar shift=100,
forget plot,
] plot coordinates { (200,1400) (600,1800) (1000,900) (1400,100)};
\end{axis}
\end{tikzpicture}
\end{document}

Bar graph alternating blue and orange

4
  • How do I place a space as a digit separator instead of a "," on numbers at least 1000? That is 1 000 instead of 1,000 for example?
    – itc
    Sep 12, 2022 at 4:27
  • 1
    With the option: /pgf/number format/1000 sep={\,} Sep 12, 2022 at 4:45
  • Do i put the option under pgfplots or tikzpicture?
    – itc
    Sep 12, 2022 at 4:49
  • 1
    Either axis or tikzpicture where ever you want it to be applied Sep 12, 2022 at 4:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .