I know how to draw a density histogram using pgfplots from this answer: Is it possible to "transform" a histogram into a density plot in pgfplots?.

But how can I draw an estimate line on the histogram like this?

enter image description here

    every axis plot post/.style={
    trim axis left

\begin{axis}[ymin=0, title=\texttt{hist=density}]
\addplot [hist=density] table [y index=0] {random.txt};
  • 5
    Could you post an MWE of what you have tried so far (at least something people can work with and expand)? Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on.
    – moewe
    Feb 17, 2014 at 7:38
  • 1
    The smooth histogram depends on a certain Kernel and a bandwidth. I would suggest to use an external programm for the calculation and import the data. Using knitr (and R) or a shell command from within latex could be helpful.
    – jens_bo
    Feb 17, 2014 at 10:12

1 Answer 1


You can use gnuplot to do the kernel density estimate:


\addplot [
] table [y index=0] {random.tsv};
\addplot [thick] gnuplot [raw gnuplot] {plot 'random.tsv' u 1:(1./1000.) smooth kdensity};
  • 3
    How did you run it? I don't know how to work with pgfplots codes which include gnuplot.
    – enthu
    Nov 10, 2014 at 14:08

You must log in to answer this question.

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