0

I have a set of random data. I could easily make a histogram in Mathematica as enter image description here Then I tried to replot this histogram in latex using the pgfplots package. But I only got enter image description here The important thing that was lost in this plot is the number of data within each bar. I don't know how can I do that. I need help to

  1. place those numbers on each bar
  2. insert more bars as it was made in the Mathematica.

The data file can be downloaded from here and here is my latex code for the histogram

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.17}
\usepgfplotslibrary{statistics}
\begin{document}

\begin{tikzpicture} \begin{axis}[small,ymin=0,title=\texttt{Histogram}] \addplot [ hist, fill=orange!75, draw=orange!50!black] table [y index=0] {data.dat}; \end{axis} \end{tikzpicture}

\end{document}

AYBRXQD
  • 737

1 Answers1

1

place those numbers on each bar

can be achieved by

nodes near coords

insert more bars as it was made in the Mathematica.

can be achieved by

hist={bins=25}

or any other number you want.

I took the liberty to enlarge the histogram so the numbers would fit.

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=17cm,compat=1.17}
\usepgfplotslibrary{statistics}
\begin{document}

\begin{tikzpicture} \begin{axis}[ymin=0,title=\texttt{Histogram}] \addplot [ hist={bins=25}, nodes near coords, fill=orange!75, draw=orange!50!black] table [y index=0] {data.dat}; \end{axis} \end{tikzpicture}

\end{document}

enter image description here

Hasan Zakeri
  • 1,942
  • Dear @Hasan_Zakeri, Thanks for your answer. how shall I remove the last number? As is seen, the last one is redundant. – AYBRXQD Mar 31 '22 at 09:36
  • 1
    See https://tex.stackexchange.com/questions/531470/problem-in-creating-a-histogram-having-number-of-occurrence-the-top-of-each-bar – Hasan Zakeri Apr 02 '22 at 08:43