1

I am trying to recreate a histogram with pgfplots in TeX that i have orignaly created with Excel: The histogram i want to recreate

The problem that i have is that i don't know how to recreate the x-axis with pgfplots. So far I have achieved the following:

My current histogram

Minimal working example with the current histogram:

\documentclass[12pt, DIV=12, paper=A4]{scrreprt}

\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{statistics}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[ 
        ybar,   
        ymajorgrids,
        axis lines*        = left,
        width              = \linewidth,
        ytick style        = {draw=none},
        enlargelimits      = 0.15,
        xtick              = {750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000},
        symbolic x coords  = {750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000},
        x tick label style = {rotate=90,anchor=east},
        legend style       = {at={(0.5,1.03)}, anchor=south, legend columns = -1},
        ]
        
        \addplot[red!20!black,fill=red!80!white] coordinates {(750,114) (760,252) (770,326) (780,363) (790,341) (800,306) (810,497) (820,2728) (830,1750) (840,372) (850,277) (860,210) (870,294) (880,191) (890,208) (900,129) (910,143) (920,98) (930,89) (940,103) (950,105) (960, 54) (970, 35) (980,24) (990,20) (1000,75)};   
                
    \end{axis}
\end{tikzpicture}

\end{document}

The documentation shows how you can create intervalls with:

xticklabel={
$[\pgfmathprintnumber\tick,
\pgfmathprintnumber\nexttick)$
},

but i am not sure how i can add the less than equal and greater than symbols to these intervalls.

I am very grateful for your help!

0

1 Answer 1

1

If you really really want, then you can jump on PGFPlots to imitate Excel. Excel is a really good spreadsheet, but produce very poor/wrong visual output.

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        ybar, bar width=9,
        ymajorgrids,
        axis lines*= left,
        width=\linewidth,
        xtick style= {draw=none}, ytick style= {draw=none},
        enlargelimits=0.15,
        xtick={750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990,1000},
        x tick label style = {rotate=90, yshift=1ex, font=\tiny},
        x tick label as interval=true,
        xticklabel={$(\pgfmathprintnumber{\tick}, \pgfmathprintnumber{\nexttick}]$},
        extra x ticks={1000,1010},
        extra x tick label={> \pgfmathprintnumber{\tick}},
        x tick label style = {/pgf/number format/set thousands separator={.}},
        y tick label style = {/pgf/number format/set thousands separator={\,}},
                 ]  
        \addplot[draw=blue!50, fill=blue!50] coordinates {(750,114) (760,252) (770,326) (780,363) (790,341) (800,306) (810,497) (820,2728) (830,1750) (840,372) (850,277) (860,210) (870,294) (880,191) (890,208) (900,129) (910,143) (920,98) (930,89) (940,103) (950,105) (960, 54) (970, 35) (980,24) (990,20) (1000,75)};   
    \end{axis}
\end{tikzpicture}
\end{document}

Bargraph in Excel style

1
  • Thank you very much @hpekristiansen for this amazing answer! I already used pgfplots to create some diagrams but i still have a lot to learn.
    – mab0189
    Commented Jul 17, 2021 at 13:47

You must log in to answer this question.

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